<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">{-
(c) The AQUA Project, Glasgow University, 1993-1998

The simplifier utilities
-}</span><span>
</span><span id="line-6"></span><span>
</span><span id="line-7"></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-8"></span><span>
</span><span id="line-9"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Core.Opt.Simplify.Utils</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-10"></span><span>        </span><span class="hs-comment">-- Rebuilding</span><span>
</span><span id="line-11"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkLam"><span class="hs-identifier">mkLam</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase"><span class="hs-identifier">mkCase</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#prepareAlts"><span class="hs-identifier">prepareAlts</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#tryEtaExpandRhs"><span class="hs-identifier">tryEtaExpandRhs</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-12"></span><span>
</span><span id="line-13"></span><span>        </span><span class="hs-comment">-- Inlining,</span><span>
</span><span id="line-14"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#preInlineUnconditionally"><span class="hs-identifier">preInlineUnconditionally</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#postInlineUnconditionally"><span class="hs-identifier">postInlineUnconditionally</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-15"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#activeUnfolding"><span class="hs-identifier">activeUnfolding</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#activeRule"><span class="hs-identifier">activeRule</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-16"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#getUnfoldingInRuleMatch"><span class="hs-identifier">getUnfoldingInRuleMatch</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-17"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#simplEnvForGHCi"><span class="hs-identifier">simplEnvForGHCi</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#updModeForStableUnfoldings"><span class="hs-identifier">updModeForStableUnfoldings</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#updModeForRules"><span class="hs-identifier">updModeForRules</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-18"></span><span>
</span><span id="line-19"></span><span>        </span><span class="hs-comment">-- The continuation type</span><span>
</span><span id="line-20"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier">SimplCont</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#DupFlag"><span class="hs-identifier">DupFlag</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StaticEnv"><span class="hs-identifier">StaticEnv</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-21"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#isSimplified"><span class="hs-identifier">isSimplified</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsStop"><span class="hs-identifier">contIsStop</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-22"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsDupable"><span class="hs-identifier">contIsDupable</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier">contResultType</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleType"><span class="hs-identifier">contHoleType</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier">contHoleScaling</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-23"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsTrivial"><span class="hs-identifier">contIsTrivial</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contArgs"><span class="hs-identifier">contArgs</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-24"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#countArgs"><span class="hs-identifier">countArgs</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-25"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkBoringStop"><span class="hs-identifier">mkBoringStop</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkRhsStop"><span class="hs-identifier">mkRhsStop</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkLazyArgStop"><span class="hs-identifier">mkLazyArgStop</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsRhsOrArg"><span class="hs-identifier">contIsRhsOrArg</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-26"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#interestingCallContext"><span class="hs-identifier">interestingCallContext</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-27"></span><span>
</span><span id="line-28"></span><span>        </span><span class="hs-comment">-- ArgInfo</span><span>
</span><span id="line-29"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier">ArgInfo</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgSpec"><span class="hs-identifier">ArgSpec</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkArgInfo"><span class="hs-identifier">mkArgInfo</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-30"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#addValArgTo"><span class="hs-identifier">addValArgTo</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#addCastTo"><span class="hs-identifier">addCastTo</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#addTyArgTo"><span class="hs-identifier">addTyArgTo</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-31"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#argInfoExpr"><span class="hs-identifier">argInfoExpr</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#argInfoAppArgs"><span class="hs-identifier">argInfoAppArgs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#pushSimplifiedArgs"><span class="hs-identifier">pushSimplifiedArgs</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-32"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#isStrictArgInfo"><span class="hs-identifier">isStrictArgInfo</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#lazyArgContext"><span class="hs-identifier">lazyArgContext</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-33"></span><span>
</span><span id="line-34"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#abstractFloats"><span class="hs-identifier">abstractFloats</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-35"></span><span>
</span><span id="line-36"></span><span>        </span><span class="hs-comment">-- Utilities</span><span>
</span><span id="line-37"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#isExitJoinId"><span class="hs-identifier">isExitJoinId</span></a></span><span>
</span><span id="line-38"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span class="hs-cpp">

#include &quot;HsVersions.h&quot;
</span><span>
</span><span id="line-42"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-43"></span><span>
</span><span id="line-44"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html"><span class="hs-identifier">GHC.Core.Opt.Simplify.Env</span></a></span><span>
</span><span id="line-45"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Monad.html"><span class="hs-identifier">GHC.Core.Opt.Monad</span></a></span><span>        </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Monad.html#SimplMode"><span class="hs-identifier">SimplMode</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Monad.html#Tick"><span class="hs-identifier">Tick</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-46"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html"><span class="hs-identifier">GHC.Driver.Session</span></a></span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.html"><span class="hs-identifier">GHC.Core</span></a></span><span>
</span><span id="line-48"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="GHC.Core.Subst.html"><span class="hs-identifier">GHC.Core.Subst</span></a></span><span>
</span><span id="line-49"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Ppr.html"><span class="hs-identifier">GHC.Core.Ppr</span></a></span><span>
</span><span id="line-50"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Ppr.html"><span class="hs-identifier">GHC.Core.TyCo.Ppr</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Ppr.html#pprParendType"><span class="hs-identifier">pprParendType</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.FVs.html"><span class="hs-identifier">GHC.Core.FVs</span></a></span><span>
</span><span id="line-52"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Utils.html"><span class="hs-identifier">GHC.Core.Utils</span></a></span><span>
</span><span id="line-53"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Arity.html"><span class="hs-identifier">GHC.Core.Opt.Arity</span></a></span><span>
</span><span id="line-54"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html"><span class="hs-identifier">GHC.Core.Unfold</span></a></span><span>
</span><span id="line-55"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Name.html"><span class="hs-identifier">GHC.Types.Name</span></a></span><span>
</span><span id="line-56"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Id.html"><span class="hs-identifier">GHC.Types.Id</span></a></span><span>
</span><span id="line-57"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Id.Info.html"><span class="hs-identifier">GHC.Types.Id.Info</span></a></span><span>
</span><span id="line-58"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.html"><span class="hs-identifier">GHC.Types.Var</span></a></span><span>
</span><span id="line-59"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html"><span class="hs-identifier">GHC.Types.Demand</span></a></span><span>
</span><span id="line-60"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html"><span class="hs-identifier">GHC.Types.Var.Set</span></a></span><span>
</span><span id="line-61"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html"><span class="hs-identifier">GHC.Types.Basic</span></a></span><span>
</span><span id="line-62"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Monad.html"><span class="hs-identifier">GHC.Core.Opt.Simplify.Monad</span></a></span><span>
</span><span id="line-63"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Type.html"><span class="hs-identifier">GHC.Core.Type</span></a></span><span>     </span><span class="hs-keyword">hiding</span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Subst.html#substTy"><span class="hs-identifier">substTy</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-64"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.html"><span class="hs-identifier">GHC.Core.Coercion</span></a></span><span> </span><span class="hs-keyword">hiding</span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Subst.html#substCo"><span class="hs-identifier">substCo</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-65"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.DataCon.html"><span class="hs-identifier">GHC.Core.DataCon</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.DataCon.html#dataConWorkId"><span class="hs-identifier">dataConWorkId</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.DataCon.html#isNullaryRepDataCon"><span class="hs-identifier">isNullaryRepDataCon</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-66"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Multiplicity.html"><span class="hs-identifier">GHC.Core.Multiplicity</span></a></span><span>
</span><span id="line-67"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html"><span class="hs-identifier">GHC.Utils.Misc</span></a></span><span>
</span><span id="line-68"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.OrdList.html"><span class="hs-identifier">GHC.Data.OrdList</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Data.OrdList.html#isNilOL"><span class="hs-identifier">isNilOL</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-69"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Monad.html"><span class="hs-identifier">GHC.Utils.Monad</span></a></span><span>
</span><span id="line-70"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span>
</span><span id="line-71"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Opt.ConstantFold.html"><span class="hs-identifier">GHC.Core.Opt.ConstantFold</span></a></span><span>
</span><span id="line-72"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.FastString.html"><span class="hs-identifier">GHC.Data.FastString</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Data.FastString.html#fsLit"><span class="hs-identifier">fsLit</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-73"></span><span>
</span><span id="line-74"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Monad.html#"><span class="hs-identifier">Control.Monad</span></a></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier">when</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-75"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.List.html#"><span class="hs-identifier">Data.List</span></a></span><span>        </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/Data.OldList.html#sortBy"><span class="hs-identifier">sortBy</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-76"></span><span>
</span><span id="line-77"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
                The SimplCont and DupFlag types
*                                                                      *
************************************************************************

A SimplCont allows the simplifier to traverse the expression in a
zipper-like fashion.  The SimplCont represents the rest of the expression,
&quot;above&quot; the point of interest.

You can also think of a SimplCont as an &quot;evaluation context&quot;, using
that term in the way it is used for operational semantics. This is the
way I usually think of it, For example you'll often see a syntax for
evaluation context looking like
        C ::= []  |  C e   |  case C of alts  |  C `cast` co
That's the kind of thing we are doing here, and I use that syntax in
the comments.


Key points:
  * A SimplCont describes a *strict* context (just like
    evaluation contexts do).  E.g. Just [] is not a SimplCont

  * A SimplCont describes a context that *does not* bind
    any variables.  E.g. \x. [] is not a SimplCont
-}</span><span>
</span><span id="line-104"></span><span>
</span><span id="line-105"></span><span class="hs-keyword">data</span><span> </span><span id="SimplCont"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-var">SimplCont</span></a></span></span><span>
</span><span id="line-106"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="Stop"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-var">Stop</span></a></span></span><span>                </span><span class="hs-comment">-- Stop[e] = e</span><span>
</span><span id="line-107"></span><span>        </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span>         </span><span class="hs-comment">-- Type of the &lt;hole&gt;</span><span>
</span><span id="line-108"></span><span>        </span><span class="annot"><a href="GHC.Core.Unfold.html#CallCtxt"><span class="hs-identifier hs-type">CallCtxt</span></a></span><span>        </span><span class="hs-comment">-- Tells if there is something interesting about</span><span>
</span><span id="line-109"></span><span>                        </span><span class="hs-comment">--          the context, and hence the inliner</span><span>
</span><span id="line-110"></span><span>                        </span><span class="hs-comment">--          should be a bit keener (see interestingCallContext)</span><span>
</span><span id="line-111"></span><span>                        </span><span class="hs-comment">-- Specifically:</span><span>
</span><span id="line-112"></span><span>                        </span><span class="hs-comment">--     This is an argument of a function that has RULES</span><span>
</span><span id="line-113"></span><span>                        </span><span class="hs-comment">--     Inlining the call might allow the rule to fire</span><span>
</span><span id="line-114"></span><span>                        </span><span class="hs-comment">-- Never ValAppCxt (use ApplyToVal instead)</span><span>
</span><span id="line-115"></span><span>                        </span><span class="hs-comment">-- or CaseCtxt (use Select instead)</span><span>
</span><span id="line-116"></span><span>
</span><span id="line-117"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="CastIt"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastIt"><span class="hs-identifier hs-var">CastIt</span></a></span></span><span>              </span><span class="hs-comment">-- (CastIt co K)[e] = K[ e `cast` co ]</span><span>
</span><span id="line-118"></span><span>        </span><span class="annot"><a href="GHC.Core.html#OutCoercion"><span class="hs-identifier hs-type">OutCoercion</span></a></span><span>             </span><span class="hs-comment">-- The coercion simplified</span><span>
</span><span id="line-119"></span><span>                                </span><span class="hs-comment">-- Invariant: never an identity coercion</span><span>
</span><span id="line-120"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span>
</span><span id="line-121"></span><span>
</span><span id="line-122"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="ApplyToVal"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToVal"><span class="hs-identifier hs-var">ApplyToVal</span></a></span></span><span>         </span><span class="hs-comment">-- (ApplyToVal arg K)[e] = K[ e arg ]</span><span>
</span><span id="line-123"></span><span>      </span><span class="hs-special">{</span><span> </span><span id="sc_dup"><span class="annot"><span class="annottext">SimplCont -&gt; DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_dup"><span class="hs-identifier hs-var hs-var">sc_dup</span></a></span></span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#DupFlag"><span class="hs-identifier hs-type">DupFlag</span></a></span><span>   </span><span class="hs-comment">-- See Note [DupFlag invariants]</span><span>
</span><span id="line-124"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_hole_ty"><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_hole_ty"><span class="hs-identifier hs-var hs-var">sc_hole_ty</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span>   </span><span class="hs-comment">-- Type of the function, presumably (forall a. blah)</span><span>
</span><span id="line-125"></span><span>                                </span><span class="hs-comment">-- See Note [The hole type in ApplyToTy/Val]</span><span>
</span><span id="line-126"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_arg"><span class="annot"><span class="annottext">SimplCont -&gt; Expr Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_arg"><span class="hs-identifier hs-var hs-var">sc_arg</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#InExpr"><span class="hs-identifier hs-type">InExpr</span></a></span><span>       </span><span class="hs-comment">-- The argument,</span><span>
</span><span id="line-127"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_env"><span class="annot"><span class="annottext">SimplCont -&gt; StaticEnv
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_env"><span class="hs-identifier hs-var hs-var">sc_env</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StaticEnv"><span class="hs-identifier hs-type">StaticEnv</span></a></span><span>    </span><span class="hs-comment">-- see Note [StaticEnv invariant]</span><span>
</span><span id="line-128"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_cont"><span class="annot"><span class="annottext">SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var hs-var">sc_cont</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-129"></span><span>
</span><span id="line-130"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="ApplyToTy"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToTy"><span class="hs-identifier hs-var">ApplyToTy</span></a></span></span><span>          </span><span class="hs-comment">-- (ApplyToTy ty K)[e] = K[ e ty ]</span><span>
</span><span id="line-131"></span><span>      </span><span class="hs-special">{</span><span> </span><span id="sc_arg_ty"><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_arg_ty"><span class="hs-identifier hs-var hs-var">sc_arg_ty</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span>     </span><span class="hs-comment">-- Argument type</span><span>
</span><span id="line-132"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_hole_ty"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#sc_hole_ty"><span class="hs-identifier hs-var">sc_hole_ty</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span>     </span><span class="hs-comment">-- Type of the function, presumably (forall a. blah)</span><span>
</span><span id="line-133"></span><span>                                  </span><span class="hs-comment">-- See Note [The hole type in ApplyToTy/Val]</span><span>
</span><span id="line-134"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_cont"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-135"></span><span>
</span><span id="line-136"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="Select"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Select"><span class="hs-identifier hs-var">Select</span></a></span></span><span>             </span><span class="hs-comment">-- (Select alts K)[e] = K[ case e of alts ]</span><span>
</span><span id="line-137"></span><span>      </span><span class="hs-special">{</span><span> </span><span id="sc_dup"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#sc_dup"><span class="hs-identifier hs-var">sc_dup</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#DupFlag"><span class="hs-identifier hs-type">DupFlag</span></a></span><span>        </span><span class="hs-comment">-- See Note [DupFlag invariants]</span><span>
</span><span id="line-138"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_bndr"><span class="annot"><span class="annottext">SimplCont -&gt; Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_bndr"><span class="hs-identifier hs-var hs-var">sc_bndr</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#InId"><span class="hs-identifier hs-type">InId</span></a></span><span>           </span><span class="hs-comment">-- case binder</span><span>
</span><span id="line-139"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_alts"><span class="annot"><span class="annottext">SimplCont -&gt; [InAlt]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_alts"><span class="hs-identifier hs-var hs-var">sc_alts</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#InAlt"><span class="hs-identifier hs-type">InAlt</span></a></span><span class="hs-special">]</span><span>        </span><span class="hs-comment">-- Alternatives</span><span>
</span><span id="line-140"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_env"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#sc_env"><span class="hs-identifier hs-var">sc_env</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StaticEnv"><span class="hs-identifier hs-type">StaticEnv</span></a></span><span>      </span><span class="hs-comment">-- See Note [StaticEnv invariant]</span><span>
</span><span id="line-141"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_cont"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-142"></span><span>
</span><span id="line-143"></span><span>  </span><span class="hs-comment">-- The two strict forms have no DupFlag, because we never duplicate them</span><span>
</span><span id="line-144"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="StrictBind"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictBind"><span class="hs-identifier hs-var">StrictBind</span></a></span></span><span>          </span><span class="hs-comment">-- (StrictBind x xs b K)[e] = let x = e in K[\xs.b]</span><span>
</span><span id="line-145"></span><span>                        </span><span class="hs-comment">--       or, equivalently,  = K[ (\x xs.b) e ]</span><span>
</span><span id="line-146"></span><span>      </span><span class="hs-special">{</span><span> </span><span id="sc_dup"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#sc_dup"><span class="hs-identifier hs-var">sc_dup</span></a></span></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#DupFlag"><span class="hs-identifier hs-type">DupFlag</span></a></span><span>        </span><span class="hs-comment">-- See Note [DupFlag invariants]</span><span>
</span><span id="line-147"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_bndr"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#sc_bndr"><span class="hs-identifier hs-var">sc_bndr</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#InId"><span class="hs-identifier hs-type">InId</span></a></span><span>
</span><span id="line-148"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_bndrs"><span class="annot"><span class="annottext">SimplCont -&gt; [Id]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_bndrs"><span class="hs-identifier hs-var hs-var">sc_bndrs</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#InBndr"><span class="hs-identifier hs-type">InBndr</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-149"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_body"><span class="annot"><span class="annottext">SimplCont -&gt; Expr Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_body"><span class="hs-identifier hs-var hs-var">sc_body</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#InExpr"><span class="hs-identifier hs-type">InExpr</span></a></span><span>
</span><span id="line-150"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_env"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#sc_env"><span class="hs-identifier hs-var">sc_env</span></a></span></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StaticEnv"><span class="hs-identifier hs-type">StaticEnv</span></a></span><span>      </span><span class="hs-comment">-- See Note [StaticEnv invariant]</span><span>
</span><span id="line-151"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_cont"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-152"></span><span>
</span><span id="line-153"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="StrictArg"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictArg"><span class="hs-identifier hs-var">StrictArg</span></a></span></span><span>           </span><span class="hs-comment">-- (StrictArg (f e1 ..en) K)[e] = K[ f e1 .. en e ]</span><span>
</span><span id="line-154"></span><span>      </span><span class="hs-special">{</span><span> </span><span id="sc_dup"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#sc_dup"><span class="hs-identifier hs-var">sc_dup</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#DupFlag"><span class="hs-identifier hs-type">DupFlag</span></a></span><span>     </span><span class="hs-comment">-- Always Simplified or OkToDup</span><span>
</span><span id="line-155"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_fun"><span class="annot"><span class="annottext">SimplCont -&gt; ArgInfo
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_fun"><span class="hs-identifier hs-var hs-var">sc_fun</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span>     </span><span class="hs-comment">-- Specifies f, e1..en, Whether f has rules, etc</span><span>
</span><span id="line-156"></span><span>                               </span><span class="hs-comment">--     plus demands and discount flags for *this* arg</span><span>
</span><span id="line-157"></span><span>                               </span><span class="hs-comment">--          and further args</span><span>
</span><span id="line-158"></span><span>                               </span><span class="hs-comment">--     So ai_dmds and ai_discs are never empty</span><span>
</span><span id="line-159"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_fun_ty"><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_fun_ty"><span class="hs-identifier hs-var hs-var">sc_fun_ty</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span>   </span><span class="hs-comment">-- Type of the function (f e1 .. en),</span><span>
</span><span id="line-160"></span><span>                               </span><span class="hs-comment">-- presumably (arg_ty -&gt; res_ty)</span><span>
</span><span id="line-161"></span><span>                               </span><span class="hs-comment">-- where res_ty is expected by sc_cont</span><span>
</span><span id="line-162"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="sc_cont"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-163"></span><span>
</span><span id="line-164"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="TickIt"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#TickIt"><span class="hs-identifier hs-var">TickIt</span></a></span></span><span>              </span><span class="hs-comment">-- (TickIt t K)[e] = K[ tick t e ]</span><span>
</span><span id="line-165"></span><span>        </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tickish"><span class="hs-identifier hs-type">Tickish</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">)</span><span>    </span><span class="hs-comment">-- Tick tickish &lt;hole&gt;</span><span>
</span><span id="line-166"></span><span>        </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span>
</span><span id="line-167"></span><span>
</span><span id="line-168"></span><span class="hs-keyword">type</span><span> </span><span id="StaticEnv"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StaticEnv"><span class="hs-identifier hs-var">StaticEnv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#SimplEnv"><span class="hs-identifier hs-type">SimplEnv</span></a></span><span>       </span><span class="hs-comment">-- Just the static part is relevant</span><span>
</span><span id="line-169"></span><span>
</span><span id="line-170"></span><span class="hs-keyword">data</span><span> </span><span id="DupFlag"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#DupFlag"><span class="hs-identifier hs-var">DupFlag</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="NoDup"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#NoDup"><span class="hs-identifier hs-var">NoDup</span></a></span></span><span>       </span><span class="hs-comment">-- Unsimplified, might be big</span><span>
</span><span id="line-171"></span><span>             </span><span class="hs-glyph">|</span><span> </span><span id="Simplified"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Simplified"><span class="hs-identifier hs-var">Simplified</span></a></span></span><span>  </span><span class="hs-comment">-- Simplified</span><span>
</span><span id="line-172"></span><span>             </span><span class="hs-glyph">|</span><span> </span><span id="OkToDup"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#OkToDup"><span class="hs-identifier hs-var">OkToDup</span></a></span></span><span>     </span><span class="hs-comment">-- Simplified and small</span><span>
</span><span id="line-173"></span><span>
</span><span id="line-174"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#isSimplified"><span class="hs-identifier hs-type">isSimplified</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#DupFlag"><span class="hs-identifier hs-type">DupFlag</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-175"></span><span id="isSimplified"><span class="annot"><span class="annottext">isSimplified :: DupFlag -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#isSimplified"><span class="hs-identifier hs-var hs-var">isSimplified</span></a></span></span><span> </span><span class="annot"><span class="annottext">DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#NoDup"><span class="hs-identifier hs-var">NoDup</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-176"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#isSimplified"><span class="hs-identifier hs-var">isSimplified</span></a></span><span> </span><span class="annot"><span class="annottext">DupFlag
</span><span class="hs-identifier">_</span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>       </span><span class="hs-comment">-- Invariant: the subst-env is empty</span><span>
</span><span id="line-177"></span><span>
</span><span id="line-178"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#perhapsSubstTy"><span class="hs-identifier hs-type">perhapsSubstTy</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#DupFlag"><span class="hs-identifier hs-type">DupFlag</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StaticEnv"><span class="hs-identifier hs-type">StaticEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span>
</span><span id="line-179"></span><span id="perhapsSubstTy"><span class="annot"><span class="annottext">perhapsSubstTy :: DupFlag -&gt; StaticEnv -&gt; OutType -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#perhapsSubstTy"><span class="hs-identifier hs-var hs-var">perhapsSubstTy</span></a></span></span><span> </span><span id="local-6989586621680969722"><span class="annot"><span class="annottext">DupFlag
</span><a href="#local-6989586621680969722"><span class="hs-identifier hs-var">dup</span></a></span></span><span> </span><span id="local-6989586621680969721"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969721"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680969720"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969720"><span class="hs-identifier hs-var">ty</span></a></span></span><span>
</span><span id="line-180"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">DupFlag -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#isSimplified"><span class="hs-identifier hs-var">isSimplified</span></a></span><span> </span><span class="annot"><span class="annottext">DupFlag
</span><a href="#local-6989586621680969722"><span class="hs-identifier hs-var">dup</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969720"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-181"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; OutType -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Env.html#substTy"><span class="hs-identifier hs-var">substTy</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969721"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969720"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-182"></span><span>
</span><span id="line-183"></span><span class="hs-comment">{- Note [StaticEnv invariant]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We pair up an InExpr or InAlts with a StaticEnv, which establishes the
lexical scope for that InExpr.  When we simplify that InExpr/InAlts, we
use
  - Its captured StaticEnv
  - Overriding its InScopeSet with the larger one at the
    simplification point.

Why override the InScopeSet?  Example:
      (let y = ey in f) ex
By the time we simplify ex, 'y' will be in scope.

However the InScopeSet in the StaticEnv is not irrelevant: it should
include all the free vars of applying the substitution to the InExpr.
Reason: contHoleType uses perhapsSubstTy to apply the substitution to
the expression, and that (rightly) gives ASSERT failures if the InScopeSet
isn't big enough.

Note [DupFlag invariants]
~~~~~~~~~~~~~~~~~~~~~~~~~
In both (ApplyToVal dup _ env k)
   and  (Select dup _ _ env k)
the following invariants hold

  (a) if dup = OkToDup, then continuation k is also ok-to-dup
  (b) if dup = OkToDup or Simplified, the subst-env is empty
      (and hence no need to re-simplify)
-}</span><span>
</span><span id="line-212"></span><span>
</span><span id="line-213"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680969716"><span class="annot"><a href="GHC.Utils.Outputable.html#Outputable"><span class="hs-identifier hs-type">Outputable</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#DupFlag"><span class="hs-identifier hs-type">DupFlag</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-214"></span><span>  </span><span id="local-6989586621680969714"><span class="annot"><span class="annottext">ppr :: DupFlag -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var hs-var hs-var hs-var">ppr</span></a></span></span><span> </span><span class="annot"><span class="annottext">DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#OkToDup"><span class="hs-identifier hs-var">OkToDup</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ok&quot;</span></span><span>
</span><span id="line-215"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#NoDup"><span class="hs-identifier hs-var">NoDup</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;nodup&quot;</span></span><span>
</span><span id="line-216"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#Simplified"><span class="hs-identifier hs-var">Simplified</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;simpl&quot;</span></span><span>
</span><span id="line-217"></span><span>
</span><span id="line-218"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680969709"><span class="annot"><a href="GHC.Utils.Outputable.html#Outputable"><span class="hs-identifier hs-type">Outputable</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-219"></span><span>  </span><span id="local-6989586621680969680"><span class="annot"><span class="annottext">ppr :: SimplCont -&gt; SDoc
</span><a href="#local-6989586621680969680"><span class="hs-identifier hs-var hs-var hs-var hs-var">ppr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-type">Stop</span></a></span><span> </span><span id="local-6989586621680969679"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969679"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span id="local-6989586621680969678"><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680969678"><span class="hs-identifier hs-var">interesting</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Stop&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#brackets"><span class="hs-identifier hs-var">brackets</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CallCtxt -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680969678"><span class="hs-identifier hs-var">interesting</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">OutType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969679"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-220"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastIt"><span class="hs-identifier hs-type">CastIt</span></a></span><span> </span><span id="local-6989586621680969674"><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969674"><span class="hs-identifier hs-var">co</span></a></span></span><span> </span><span id="local-6989586621680969673"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969673"><span class="hs-identifier hs-var">cont</span></a></span></span><span>  </span><span class="hs-special">)</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;CastIt&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion -&gt; SDoc
</span><a href="GHC.Core.Ppr.html#pprOptCo"><span class="hs-identifier hs-var">pprOptCo</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969674"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969673"><span class="hs-identifier hs-var">cont</span></a></span><span>
</span><span id="line-221"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#TickIt"><span class="hs-identifier hs-type">TickIt</span></a></span><span> </span><span id="local-6989586621680969670"><span class="annot"><span class="annottext">Tickish Id
</span><a href="#local-6989586621680969670"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span id="local-6989586621680969669"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969669"><span class="hs-identifier hs-var">cont</span></a></span></span><span class="hs-special">)</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;TickIt&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><a href="#local-6989586621680969670"><span class="hs-identifier hs-var">t</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969669"><span class="hs-identifier hs-var">cont</span></a></span><span>
</span><span id="line-222"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToTy"><span class="hs-identifier hs-type">ApplyToTy</span></a></span><span>  </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_arg_ty :: SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_arg_ty"><span class="hs-identifier hs-var">sc_arg_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969668"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969668"><span class="hs-identifier hs-var">ty</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969667"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969667"><span class="hs-identifier hs-var">cont</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-223"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ApplyToTy&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">OutType -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprParendType"><span class="hs-identifier hs-var">pprParendType</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969668"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969667"><span class="hs-identifier hs-var">cont</span></a></span><span>
</span><span id="line-224"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToVal"><span class="hs-identifier hs-type">ApplyToVal</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_arg :: SimplCont -&gt; Expr Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_arg"><span class="hs-identifier hs-var">sc_arg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969666"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969666"><span class="hs-identifier hs-var">arg</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_dup :: SimplCont -&gt; DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_dup"><span class="hs-identifier hs-var">sc_dup</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969665"><span class="annot"><span class="annottext">DupFlag
</span><a href="#local-6989586621680969665"><span class="hs-identifier hs-var">dup</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969664"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969664"><span class="hs-identifier hs-var">cont</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_hole_ty :: SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_hole_ty"><span class="hs-identifier hs-var">sc_hole_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969663"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969663"><span class="hs-identifier hs-var">hole_ty</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-225"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SDoc -&gt; Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#hang"><span class="hs-identifier hs-var">hang</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ApplyToVal&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">DupFlag -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">DupFlag
</span><a href="#local-6989586621680969665"><span class="hs-identifier hs-var">dup</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hole&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">OutType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969663"><span class="hs-identifier hs-var">hole_ty</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-226"></span><span>          </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Expr Id -&gt; SDoc
forall b. OutputableBndr b =&gt; Expr b -&gt; SDoc
</span><a href="GHC.Core.Ppr.html#pprParendExpr"><span class="hs-identifier hs-var">pprParendExpr</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969666"><span class="hs-identifier hs-var">arg</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-227"></span><span>      </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969664"><span class="hs-identifier hs-var">cont</span></a></span><span>
</span><span id="line-228"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictBind"><span class="hs-identifier hs-type">StrictBind</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_bndr :: SimplCont -&gt; Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_bndr"><span class="hs-identifier hs-var">sc_bndr</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969660"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969660"><span class="hs-identifier hs-var">b</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969659"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969659"><span class="hs-identifier hs-var">cont</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-229"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;StrictBind&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969660"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969659"><span class="hs-identifier hs-var">cont</span></a></span><span>
</span><span id="line-230"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictArg"><span class="hs-identifier hs-type">StrictArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_fun :: SimplCont -&gt; ArgInfo
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_fun"><span class="hs-identifier hs-var">sc_fun</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969658"><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969658"><span class="hs-identifier hs-var">ai</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969657"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969657"><span class="hs-identifier hs-var">cont</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-231"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;StrictArg&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ArgInfo -&gt; Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_fun"><span class="hs-identifier hs-var hs-var">ai_fun</span></a></span><span> </span><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969658"><span class="hs-identifier hs-var">ai</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969657"><span class="hs-identifier hs-var">cont</span></a></span><span>
</span><span id="line-232"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Select"><span class="hs-identifier hs-type">Select</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_dup :: SimplCont -&gt; DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_dup"><span class="hs-identifier hs-var">sc_dup</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969655"><span class="annot"><span class="annottext">DupFlag
</span><a href="#local-6989586621680969655"><span class="hs-identifier hs-var">dup</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_bndr :: SimplCont -&gt; Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_bndr"><span class="hs-identifier hs-var">sc_bndr</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969654"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969654"><span class="hs-identifier hs-var">bndr</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_alts :: SimplCont -&gt; [InAlt]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_alts"><span class="hs-identifier hs-var">sc_alts</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969653"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969653"><span class="hs-identifier hs-var">alts</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_env :: SimplCont -&gt; StaticEnv
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_env"><span class="hs-identifier hs-var">sc_env</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969652"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969652"><span class="hs-identifier hs-var">se</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969651"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969651"><span class="hs-identifier hs-var">cont</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-233"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Select&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">DupFlag -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">DupFlag
</span><a href="#local-6989586621680969655"><span class="hs-identifier hs-var">dup</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969654"><span class="hs-identifier hs-var">bndr</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span>
</span><span id="line-234"></span><span>       </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#whenPprDebug"><span class="hs-identifier hs-var">whenPprDebug</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Arity -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#nest"><span class="hs-identifier hs-var">nest</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; SDoc) -&gt; SDoc -&gt; SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">TvSubstEnv -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StaticEnv -&gt; TvSubstEnv
</span><a href="GHC.Core.Opt.Simplify.Env.html#seTvSubst"><span class="hs-identifier hs-var hs-var">seTvSubst</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969652"><span class="hs-identifier hs-var">se</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[InAlt] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969653"><span class="hs-identifier hs-var">alts</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969651"><span class="hs-identifier hs-var">cont</span></a></span><span>
</span><span id="line-235"></span><span>
</span><span id="line-236"></span><span>
</span><span id="line-237"></span><span class="hs-comment">{- Note [The hole type in ApplyToTy]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The sc_hole_ty field of ApplyToTy records the type of the &quot;hole&quot; in the
continuation.  It is absolutely necessary to compute contHoleType, but it is
not used for anything else (and hence may not be evaluated).

Why is it necessary for contHoleType?  Consider the continuation
     ApplyToType Int (Stop Int)
corresponding to
     (&lt;hole&gt; @Int) :: Int
What is the type of &lt;hole&gt;?  It could be (forall a. Int) or (forall a. a),
and there is no way to know which, so we must record it.

In a chain of applications  (f @t1 @t2 @t3) we'll lazily compute exprType
for (f @t1) and (f @t1 @t2), which is potentially non-linear; but it probably
doesn't matter because we'll never compute them all.

************************************************************************
*                                                                      *
                ArgInfo and ArgSpec
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-260"></span><span>
</span><span id="line-261"></span><span class="hs-keyword">data</span><span> </span><span id="ArgInfo"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-var">ArgInfo</span></a></span></span><span>
</span><span id="line-262"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="ArgInfo"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-var">ArgInfo</span></a></span></span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-263"></span><span>        </span><span id="ai_fun"><span class="annot"><span class="annottext">ArgInfo -&gt; Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_fun"><span class="hs-identifier hs-var hs-var">ai_fun</span></a></span></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#OutId"><span class="hs-identifier hs-type">OutId</span></a></span><span class="hs-special">,</span><span>      </span><span class="hs-comment">-- The function</span><span>
</span><span id="line-264"></span><span>        </span><span id="ai_args"><span class="annot"><span class="annottext">ArgInfo -&gt; [ArgSpec]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_args"><span class="hs-identifier hs-var hs-var">ai_args</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgSpec"><span class="hs-identifier hs-type">ArgSpec</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span>  </span><span class="hs-comment">-- ...applied to these args (which are in *reverse* order)</span><span>
</span><span id="line-265"></span><span>
</span><span id="line-266"></span><span>        </span><span id="ai_rules"><span class="annot"><span class="annottext">ArgInfo -&gt; FunRules
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_rules"><span class="hs-identifier hs-var hs-var">ai_rules</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#FunRules"><span class="hs-identifier hs-type">FunRules</span></a></span><span class="hs-special">,</span><span>   </span><span class="hs-comment">-- Rules for this function</span><span>
</span><span id="line-267"></span><span>
</span><span id="line-268"></span><span>        </span><span id="ai_encl"><span class="annot"><span class="annottext">ArgInfo -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_encl"><span class="hs-identifier hs-var hs-var">ai_encl</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span class="hs-special">,</span><span>        </span><span class="hs-comment">-- Flag saying whether this function</span><span>
</span><span id="line-269"></span><span>                                </span><span class="hs-comment">-- or an enclosing one has rules (recursively)</span><span>
</span><span id="line-270"></span><span>                                </span><span class="hs-comment">--      True =&gt; be keener to inline in all args</span><span>
</span><span id="line-271"></span><span>
</span><span id="line-272"></span><span>        </span><span id="ai_dmds"><span class="annot"><span class="annottext">ArgInfo -&gt; [Demand]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_dmds"><span class="hs-identifier hs-var hs-var">ai_dmds</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Demand.html#Demand"><span class="hs-identifier hs-type">Demand</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span>    </span><span class="hs-comment">-- Demands on remaining value arguments (beyond ai_args)</span><span>
</span><span id="line-273"></span><span>                                </span><span class="hs-comment">--   Usually infinite, but if it is finite it guarantees</span><span>
</span><span id="line-274"></span><span>                                </span><span class="hs-comment">--   that the function diverges after being given</span><span>
</span><span id="line-275"></span><span>                                </span><span class="hs-comment">--   that number of args</span><span>
</span><span id="line-276"></span><span>
</span><span id="line-277"></span><span>        </span><span id="ai_discs"><span class="annot"><span class="annottext">ArgInfo -&gt; [Arity]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_discs"><span class="hs-identifier hs-var hs-var">ai_discs</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">]</span><span>       </span><span class="hs-comment">-- Discounts for remaining value arguments (beyong ai_args)</span><span>
</span><span id="line-278"></span><span>                                </span><span class="hs-comment">--   non-zero =&gt; be keener to inline</span><span>
</span><span id="line-279"></span><span>                                </span><span class="hs-comment">--   Always infinite</span><span>
</span><span id="line-280"></span><span>    </span><span class="hs-special">}</span><span>
</span><span id="line-281"></span><span>
</span><span id="line-282"></span><span class="hs-keyword">data</span><span> </span><span id="ArgSpec"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgSpec"><span class="hs-identifier hs-var">ArgSpec</span></a></span></span><span>
</span><span id="line-283"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="ValArg"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ValArg"><span class="hs-identifier hs-var">ValArg</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="as_dmd"><span class="annot"><span class="annottext">ArgSpec -&gt; Demand
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_dmd"><span class="hs-identifier hs-var hs-var">as_dmd</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#Demand"><span class="hs-identifier hs-type">Demand</span></a></span><span>        </span><span class="hs-comment">-- Demand placed on this argument</span><span>
</span><span id="line-284"></span><span>           </span><span class="hs-special">,</span><span> </span><span id="as_arg"><span class="annot"><span class="annottext">ArgSpec -&gt; Expr Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_arg"><span class="hs-identifier hs-var hs-var">as_arg</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span>       </span><span class="hs-comment">-- Apply to this (coercion or value); c.f. ApplyToVal</span><span>
</span><span id="line-285"></span><span>           </span><span class="hs-special">,</span><span> </span><span id="as_hole_ty"><span class="annot"><span class="annottext">ArgSpec -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_hole_ty"><span class="hs-identifier hs-var hs-var">as_hole_ty</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span> </span><span class="hs-special">}</span><span>  </span><span class="hs-comment">-- Type of the function (presumably t1 -&gt; t2)</span><span>
</span><span id="line-286"></span><span>
</span><span id="line-287"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="TyArg"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#TyArg"><span class="hs-identifier hs-var">TyArg</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="as_arg_ty"><span class="annot"><span class="annottext">ArgSpec -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_arg_ty"><span class="hs-identifier hs-var hs-var">as_arg_ty</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span>     </span><span class="hs-comment">-- Apply to this type; c.f. ApplyToTy</span><span>
</span><span id="line-288"></span><span>          </span><span class="hs-special">,</span><span> </span><span id="as_hole_ty"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#as_hole_ty"><span class="hs-identifier hs-var">as_hole_ty</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span> </span><span class="hs-special">}</span><span>   </span><span class="hs-comment">-- Type of the function (presumably forall a. blah)</span><span>
</span><span id="line-289"></span><span>
</span><span id="line-290"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="CastBy"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastBy"><span class="hs-identifier hs-var">CastBy</span></a></span></span><span> </span><span class="annot"><a href="GHC.Core.html#OutCoercion"><span class="hs-identifier hs-type">OutCoercion</span></a></span><span>                </span><span class="hs-comment">-- Cast by this; c.f. CastIt</span><span>
</span><span id="line-291"></span><span>
</span><span id="line-292"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680969629"><span class="annot"><a href="GHC.Utils.Outputable.html#Outputable"><span class="hs-identifier hs-type">Outputable</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-293"></span><span>  </span><span id="local-6989586621680969624"><span class="annot"><span class="annottext">ppr :: ArgInfo -&gt; SDoc
</span><a href="#local-6989586621680969624"><span class="hs-identifier hs-var hs-var hs-var hs-var">ppr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ai_fun :: ArgInfo -&gt; Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_fun"><span class="hs-identifier hs-var">ai_fun</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969623"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969623"><span class="hs-identifier hs-var">fun</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_args :: ArgInfo -&gt; [ArgSpec]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_args"><span class="hs-identifier hs-var">ai_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969622"><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969622"><span class="hs-identifier hs-var">args</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_dmds :: ArgInfo -&gt; [Demand]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_dmds"><span class="hs-identifier hs-var">ai_dmds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969621"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969621"><span class="hs-identifier hs-var">dmds</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-294"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ArgInfo&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#braces"><span class="hs-identifier hs-var">braces</span></a></span><span>
</span><span id="line-295"></span><span>         </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#sep"><span class="hs-identifier hs-var">sep</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;fun =&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969623"><span class="hs-identifier hs-var">fun</span></a></span><span>
</span><span id="line-296"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;dmds =&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969621"><span class="hs-identifier hs-var">dmds</span></a></span><span>
</span><span id="line-297"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;args =&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSpec] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969622"><span class="hs-identifier hs-var">args</span></a></span><span> </span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-298"></span><span>
</span><span id="line-299"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680969616"><span class="annot"><a href="GHC.Utils.Outputable.html#Outputable"><span class="hs-identifier hs-type">Outputable</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgSpec"><span class="hs-identifier hs-type">ArgSpec</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-300"></span><span>  </span><span id="local-6989586621680969611"><span class="annot"><span class="annottext">ppr :: ArgSpec -&gt; SDoc
</span><a href="#local-6989586621680969611"><span class="hs-identifier hs-var hs-var hs-var hs-var">ppr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ValArg"><span class="hs-identifier hs-type">ValArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">as_arg :: ArgSpec -&gt; Expr Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_arg"><span class="hs-identifier hs-var">as_arg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969610"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969610"><span class="hs-identifier hs-var">arg</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ValArg&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969610"><span class="hs-identifier hs-var">arg</span></a></span><span>
</span><span id="line-301"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#TyArg"><span class="hs-identifier hs-type">TyArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">as_arg_ty :: ArgSpec -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_arg_ty"><span class="hs-identifier hs-var">as_arg_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969609"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969609"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;TyArg&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">OutType -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969609"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-302"></span><span>  </span><span class="annot"><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastBy"><span class="hs-identifier hs-type">CastBy</span></a></span><span> </span><span id="local-6989586621680969608"><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969608"><span class="hs-identifier hs-var">c</span></a></span></span><span class="hs-special">)</span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;CastBy&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969608"><span class="hs-identifier hs-var">c</span></a></span><span>
</span><span id="line-303"></span><span>
</span><span id="line-304"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#addValArgTo"><span class="hs-identifier hs-type">addValArgTo</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span>  </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span>
</span><span id="line-305"></span><span id="addValArgTo"><span class="annot"><span class="annottext">addValArgTo :: ArgInfo -&gt; Expr Id -&gt; OutType -&gt; ArgInfo
</span><a href="GHC.Core.Opt.Simplify.Utils.html#addValArgTo"><span class="hs-identifier hs-var hs-var">addValArgTo</span></a></span></span><span> </span><span id="local-6989586621680969607"><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969607"><span class="hs-identifier hs-var">ai</span></a></span></span><span> </span><span id="local-6989586621680969606"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969606"><span class="hs-identifier hs-var">arg</span></a></span></span><span> </span><span id="local-6989586621680969605"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969605"><span class="hs-identifier hs-var">hole_ty</span></a></span></span><span>
</span><span id="line-306"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ai_dmds :: ArgInfo -&gt; [Demand]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_dmds"><span class="hs-identifier hs-var">ai_dmds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969604"><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680969604"><span class="hs-identifier hs-var">dmd</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680969603"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969603"><span class="hs-identifier hs-var">dmds</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_discs :: ArgInfo -&gt; [Arity]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_discs"><span class="hs-identifier hs-var">ai_discs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-identifier">_</span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680969602"><span class="annot"><span class="annottext">[Arity]
</span><a href="#local-6989586621680969602"><span class="hs-identifier hs-var">discs</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_rules :: ArgInfo -&gt; FunRules
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_rules"><span class="hs-identifier hs-var">ai_rules</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969601"><span class="annot"><span class="annottext">FunRules
</span><a href="#local-6989586621680969601"><span class="hs-identifier hs-var">rules</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969607"><span class="hs-identifier hs-var">ai</span></a></span><span>
</span><span id="line-307"></span><span>      </span><span class="hs-comment">-- Pop the top demand and and discounts off</span><span>
</span><span id="line-308"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680969600"><span class="annot"><span class="annottext">arg_spec :: ArgSpec
</span><a href="#local-6989586621680969600"><span class="hs-identifier hs-var hs-var">arg_spec</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ValArg :: Demand -&gt; Expr Id -&gt; OutType -&gt; ArgSpec
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ValArg"><span class="hs-identifier hs-type">ValArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">as_arg :: Expr Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_arg"><span class="hs-identifier hs-var">as_arg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969606"><span class="hs-identifier hs-var">arg</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">as_hole_ty :: OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_hole_ty"><span class="hs-identifier hs-var">as_hole_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969605"><span class="hs-identifier hs-var">hole_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">as_dmd :: Demand
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_dmd"><span class="hs-identifier hs-var">as_dmd</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680969604"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-309"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969607"><span class="hs-identifier hs-var">ai</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ai_args :: [ArgSpec]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_args"><span class="hs-identifier hs-var">ai_args</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgSpec
</span><a href="#local-6989586621680969600"><span class="hs-identifier hs-var">arg_spec</span></a></span><span> </span><span class="annot"><span class="annottext">ArgSpec -&gt; [ArgSpec] -&gt; [ArgSpec]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">ArgInfo -&gt; [ArgSpec]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_args"><span class="hs-identifier hs-var hs-var">ai_args</span></a></span><span> </span><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969607"><span class="hs-identifier hs-var">ai</span></a></span><span>
</span><span id="line-310"></span><span>       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_dmds :: [Demand]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_dmds"><span class="hs-identifier hs-var">ai_dmds</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969603"><span class="hs-identifier hs-var">dmds</span></a></span><span>
</span><span id="line-311"></span><span>       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_discs :: [Arity]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_discs"><span class="hs-identifier hs-var">ai_discs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Arity]
</span><a href="#local-6989586621680969602"><span class="hs-identifier hs-var">discs</span></a></span><span>
</span><span id="line-312"></span><span>       </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_rules :: FunRules
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_rules"><span class="hs-identifier hs-var">ai_rules</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FunRules -&gt; FunRules
</span><a href="GHC.Core.Opt.Simplify.Utils.html#decRules"><span class="hs-identifier hs-var">decRules</span></a></span><span> </span><span class="annot"><span class="annottext">FunRules
</span><a href="#local-6989586621680969601"><span class="hs-identifier hs-var">rules</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-313"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-314"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; ArgInfo
forall a. HasCallStack =&gt; String -&gt; SDoc -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprPanic"><span class="hs-identifier hs-var">pprPanic</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;addValArgTo&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ArgInfo -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969607"><span class="hs-identifier hs-var">ai</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%24%24"><span class="hs-operator hs-var">$$</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969606"><span class="hs-identifier hs-var">arg</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-315"></span><span>    </span><span class="hs-comment">-- There should always be enough demands and discounts</span><span>
</span><span id="line-316"></span><span>
</span><span id="line-317"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#addTyArgTo"><span class="hs-identifier hs-type">addTyArgTo</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span>
</span><span id="line-318"></span><span id="addTyArgTo"><span class="annot"><span class="annottext">addTyArgTo :: ArgInfo -&gt; OutType -&gt; OutType -&gt; ArgInfo
</span><a href="GHC.Core.Opt.Simplify.Utils.html#addTyArgTo"><span class="hs-identifier hs-var hs-var">addTyArgTo</span></a></span></span><span> </span><span id="local-6989586621680969597"><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969597"><span class="hs-identifier hs-var">ai</span></a></span></span><span> </span><span id="local-6989586621680969596"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969596"><span class="hs-identifier hs-var">arg_ty</span></a></span></span><span> </span><span id="local-6989586621680969595"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969595"><span class="hs-identifier hs-var">hole_ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969597"><span class="hs-identifier hs-var">ai</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ai_args :: [ArgSpec]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_args"><span class="hs-identifier hs-var">ai_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgSpec
</span><a href="#local-6989586621680969594"><span class="hs-identifier hs-var">arg_spec</span></a></span><span> </span><span class="annot"><span class="annottext">ArgSpec -&gt; [ArgSpec] -&gt; [ArgSpec]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">ArgInfo -&gt; [ArgSpec]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_args"><span class="hs-identifier hs-var hs-var">ai_args</span></a></span><span> </span><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969597"><span class="hs-identifier hs-var">ai</span></a></span><span>
</span><span id="line-319"></span><span>                                  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_rules :: FunRules
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_rules"><span class="hs-identifier hs-var">ai_rules</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FunRules -&gt; FunRules
</span><a href="GHC.Core.Opt.Simplify.Utils.html#decRules"><span class="hs-identifier hs-var">decRules</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ArgInfo -&gt; FunRules
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_rules"><span class="hs-identifier hs-var hs-var">ai_rules</span></a></span><span> </span><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969597"><span class="hs-identifier hs-var">ai</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-320"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-321"></span><span>    </span><span id="local-6989586621680969594"><span class="annot"><span class="annottext">arg_spec :: ArgSpec
</span><a href="#local-6989586621680969594"><span class="hs-identifier hs-var hs-var">arg_spec</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyArg :: OutType -&gt; OutType -&gt; ArgSpec
</span><a href="GHC.Core.Opt.Simplify.Utils.html#TyArg"><span class="hs-identifier hs-type">TyArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">as_arg_ty :: OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_arg_ty"><span class="hs-identifier hs-var">as_arg_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969596"><span class="hs-identifier hs-var">arg_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">as_hole_ty :: OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_hole_ty"><span class="hs-identifier hs-var">as_hole_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969595"><span class="hs-identifier hs-var">hole_ty</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-322"></span><span>
</span><span id="line-323"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#addCastTo"><span class="hs-identifier hs-type">addCastTo</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutCoercion"><span class="hs-identifier hs-type">OutCoercion</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span>
</span><span id="line-324"></span><span id="addCastTo"><span class="annot"><span class="annottext">addCastTo :: ArgInfo -&gt; OutCoercion -&gt; ArgInfo
</span><a href="GHC.Core.Opt.Simplify.Utils.html#addCastTo"><span class="hs-identifier hs-var hs-var">addCastTo</span></a></span></span><span> </span><span id="local-6989586621680969593"><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969593"><span class="hs-identifier hs-var">ai</span></a></span></span><span> </span><span id="local-6989586621680969592"><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969592"><span class="hs-identifier hs-var">co</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969593"><span class="hs-identifier hs-var">ai</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ai_args :: [ArgSpec]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_args"><span class="hs-identifier hs-var">ai_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutCoercion -&gt; ArgSpec
</span><a href="GHC.Core.Opt.Simplify.Utils.html#CastBy"><span class="hs-identifier hs-var">CastBy</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969592"><span class="hs-identifier hs-var">co</span></a></span><span> </span><span class="annot"><span class="annottext">ArgSpec -&gt; [ArgSpec] -&gt; [ArgSpec]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">ArgInfo -&gt; [ArgSpec]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_args"><span class="hs-identifier hs-var hs-var">ai_args</span></a></span><span> </span><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969593"><span class="hs-identifier hs-var">ai</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-325"></span><span>
</span><span id="line-326"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#isStrictArgInfo"><span class="hs-identifier hs-type">isStrictArgInfo</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-327"></span><span class="hs-comment">-- True if the function is strict in the next argument</span><span>
</span><span id="line-328"></span><span id="isStrictArgInfo"><span class="annot"><span class="annottext">isStrictArgInfo :: ArgInfo -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#isStrictArgInfo"><span class="hs-identifier hs-var hs-var">isStrictArgInfo</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ai_dmds :: ArgInfo -&gt; [Demand]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_dmds"><span class="hs-identifier hs-var">ai_dmds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969591"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969591"><span class="hs-identifier hs-var">dmds</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-329"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680969590"><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680969590"><span class="hs-identifier hs-var">dmd</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span class="annot"><span class="annottext">[Demand]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969591"><span class="hs-identifier hs-var">dmds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Demand -&gt; Bool
forall s u. JointDmd (Str s) (Use u) -&gt; Bool
</span><a href="GHC.Types.Demand.html#isStrictDmd"><span class="hs-identifier hs-var">isStrictDmd</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680969590"><span class="hs-identifier hs-var">dmd</span></a></span><span>
</span><span id="line-330"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-331"></span><span>
</span><span id="line-332"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#argInfoAppArgs"><span class="hs-identifier hs-type">argInfoAppArgs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgSpec"><span class="hs-identifier hs-type">ArgSpec</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-333"></span><span id="argInfoAppArgs"><span class="annot"><span class="annottext">argInfoAppArgs :: [ArgSpec] -&gt; [Expr Id]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#argInfoAppArgs"><span class="hs-identifier hs-var hs-var">argInfoAppArgs</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>                              </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-334"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#argInfoAppArgs"><span class="hs-identifier hs-var">argInfoAppArgs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastBy"><span class="hs-identifier hs-type">CastBy</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span>                </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span class="annot"><span class="annottext">[ArgSpec]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>  </span><span class="hs-comment">-- Stop at a cast</span><span>
</span><span id="line-335"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#argInfoAppArgs"><span class="hs-identifier hs-var">argInfoAppArgs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ValArg"><span class="hs-identifier hs-type">ValArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">as_arg :: ArgSpec -&gt; Expr Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_arg"><span class="hs-identifier hs-var">as_arg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969588"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969588"><span class="hs-identifier hs-var">arg</span></a></span></span><span> </span><span class="hs-special">}</span><span>  </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680969587"><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969587"><span class="hs-keyword hs-var">as</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969588"><span class="hs-identifier hs-var">arg</span></a></span><span>     </span><span class="annot"><span class="annottext">Expr Id -&gt; [Expr Id] -&gt; [Expr Id]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[ArgSpec] -&gt; [Expr Id]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#argInfoAppArgs"><span class="hs-identifier hs-var">argInfoAppArgs</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969587"><span class="hs-keyword hs-var">as</span></a></span><span>
</span><span id="line-336"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#argInfoAppArgs"><span class="hs-identifier hs-var">argInfoAppArgs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#TyArg"><span class="hs-identifier hs-type">TyArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">as_arg_ty :: ArgSpec -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_arg_ty"><span class="hs-identifier hs-var">as_arg_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969586"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969586"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680969585"><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969585"><span class="hs-keyword hs-var">as</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType -&gt; Expr Id
forall b. OutType -&gt; Expr b
</span><a href="GHC.Core.html#Type"><span class="hs-identifier hs-var">Type</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969586"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; [Expr Id] -&gt; [Expr Id]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[ArgSpec] -&gt; [Expr Id]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#argInfoAppArgs"><span class="hs-identifier hs-var">argInfoAppArgs</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969585"><span class="hs-keyword hs-var">as</span></a></span><span>
</span><span id="line-337"></span><span>
</span><span id="line-338"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#pushSimplifiedArgs"><span class="hs-identifier hs-type">pushSimplifiedArgs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#SimplEnv"><span class="hs-identifier hs-type">SimplEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgSpec"><span class="hs-identifier hs-type">ArgSpec</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span>
</span><span id="line-339"></span><span id="pushSimplifiedArgs"><span class="annot"><span class="annottext">pushSimplifiedArgs :: StaticEnv -&gt; [ArgSpec] -&gt; SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#pushSimplifiedArgs"><span class="hs-identifier hs-var hs-var">pushSimplifiedArgs</span></a></span></span><span> </span><span id="local-6989586621680969583"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969583"><span class="hs-identifier hs-var">_env</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>           </span><span id="local-6989586621680969582"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969582"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969582"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-340"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#pushSimplifiedArgs"><span class="hs-identifier hs-var">pushSimplifiedArgs</span></a></span><span> </span><span id="local-6989586621680969581"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969581"><span class="hs-identifier hs-var">env</span></a></span></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621680969580"><span class="annot"><span class="annottext">ArgSpec
</span><a href="#local-6989586621680969580"><span class="hs-identifier hs-var">arg</span></a></span></span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680969579"><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969579"><span class="hs-identifier hs-var">args</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680969578"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969578"><span class="hs-identifier hs-var">k</span></a></span></span><span>
</span><span id="line-341"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">ArgSpec
</span><a href="#local-6989586621680969580"><span class="hs-identifier hs-var">arg</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-342"></span><span>      </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#TyArg"><span class="hs-identifier hs-type">TyArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">as_arg_ty :: ArgSpec -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_arg_ty"><span class="hs-identifier hs-var">as_arg_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969577"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969577"><span class="hs-identifier hs-var">arg_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">as_hole_ty :: ArgSpec -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_hole_ty"><span class="hs-identifier hs-var">as_hole_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969576"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969576"><span class="hs-identifier hs-var">hole_ty</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-343"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">ApplyToTy :: OutType -&gt; OutType -&gt; SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToTy"><span class="hs-identifier hs-type">ApplyToTy</span></a></span><span>  </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_arg_ty :: OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_arg_ty"><span class="hs-identifier hs-var">sc_arg_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969577"><span class="hs-identifier hs-var">arg_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_hole_ty :: OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_hole_ty"><span class="hs-identifier hs-var">sc_hole_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969576"><span class="hs-identifier hs-var">hole_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969575"><span class="hs-identifier hs-var">rest</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-344"></span><span>      </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ValArg"><span class="hs-identifier hs-type">ValArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">as_arg :: ArgSpec -&gt; Expr Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_arg"><span class="hs-identifier hs-var">as_arg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969574"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969574"><span class="hs-identifier hs-var">arg</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">as_hole_ty :: ArgSpec -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_hole_ty"><span class="hs-identifier hs-var">as_hole_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969573"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969573"><span class="hs-identifier hs-var">hole_ty</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-345"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">ApplyToVal :: DupFlag
-&gt; OutType -&gt; Expr Id -&gt; StaticEnv -&gt; SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToVal"><span class="hs-identifier hs-type">ApplyToVal</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_arg :: Expr Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_arg"><span class="hs-identifier hs-var">sc_arg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969574"><span class="hs-identifier hs-var">arg</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_env :: StaticEnv
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_env"><span class="hs-identifier hs-var">sc_env</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969581"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_dup :: DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_dup"><span class="hs-identifier hs-var">sc_dup</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#Simplified"><span class="hs-identifier hs-var">Simplified</span></a></span><span>
</span><span id="line-346"></span><span>                           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_hole_ty :: OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_hole_ty"><span class="hs-identifier hs-var">sc_hole_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969573"><span class="hs-identifier hs-var">hole_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969575"><span class="hs-identifier hs-var">rest</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-347"></span><span>      </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastBy"><span class="hs-identifier hs-type">CastBy</span></a></span><span> </span><span id="local-6989586621680969572"><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969572"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">OutCoercion -&gt; SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#CastIt"><span class="hs-identifier hs-var">CastIt</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969572"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969575"><span class="hs-identifier hs-var">rest</span></a></span><span>
</span><span id="line-348"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-349"></span><span>    </span><span id="local-6989586621680969575"><span class="annot"><span class="annottext">rest :: SimplCont
</span><a href="#local-6989586621680969575"><span class="hs-identifier hs-var hs-var">rest</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; [ArgSpec] -&gt; SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#pushSimplifiedArgs"><span class="hs-identifier hs-var">pushSimplifiedArgs</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969581"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969579"><span class="hs-identifier hs-var">args</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969578"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-350"></span><span>           </span><span class="hs-comment">-- The env has an empty SubstEnv</span><span>
</span><span id="line-351"></span><span>
</span><span id="line-352"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#argInfoExpr"><span class="hs-identifier hs-type">argInfoExpr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#OutId"><span class="hs-identifier hs-type">OutId</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgSpec"><span class="hs-identifier hs-type">ArgSpec</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span>
</span><span id="line-353"></span><span class="hs-comment">-- NB: the [ArgSpec] is reversed so that the first arg</span><span>
</span><span id="line-354"></span><span class="hs-comment">-- in the list is the last one in the application</span><span>
</span><span id="line-355"></span><span id="argInfoExpr"><span class="annot"><span class="annottext">argInfoExpr :: Id -&gt; [ArgSpec] -&gt; Expr Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#argInfoExpr"><span class="hs-identifier hs-var hs-var">argInfoExpr</span></a></span></span><span> </span><span id="local-6989586621680969571"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969571"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621680969570"><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969570"><span class="hs-identifier hs-var">rev_args</span></a></span></span><span>
</span><span id="line-356"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ArgSpec] -&gt; Expr Id
</span><a href="#local-6989586621680969569"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969570"><span class="hs-identifier hs-var">rev_args</span></a></span><span>
</span><span id="line-357"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-358"></span><span>    </span><span id="local-6989586621680969569"><span class="annot"><span class="annottext">go :: [ArgSpec] -&gt; Expr Id
</span><a href="#local-6989586621680969569"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>                              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Expr Id
forall b. Id -&gt; Expr b
</span><a href="GHC.Core.html#Var"><span class="hs-identifier hs-var">Var</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969571"><span class="hs-identifier hs-var">fun</span></a></span><span>
</span><span id="line-359"></span><span>    </span><span class="annot"><a href="#local-6989586621680969569"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ValArg"><span class="hs-identifier hs-type">ValArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">as_arg :: ArgSpec -&gt; Expr Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_arg"><span class="hs-identifier hs-var">as_arg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969567"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969567"><span class="hs-identifier hs-var">arg</span></a></span></span><span> </span><span class="hs-special">}</span><span>  </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680969566"><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969566"><span class="hs-keyword hs-var">as</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ArgSpec] -&gt; Expr Id
</span><a href="#local-6989586621680969569"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969566"><span class="hs-keyword hs-var">as</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Expr Id -&gt; Expr Id
forall b. Expr b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#App"><span class="hs-operator hs-var">`App`</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969567"><span class="hs-identifier hs-var">arg</span></a></span><span>
</span><span id="line-360"></span><span>    </span><span class="annot"><a href="#local-6989586621680969569"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#TyArg"><span class="hs-identifier hs-type">TyArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">as_arg_ty :: ArgSpec -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#as_arg_ty"><span class="hs-identifier hs-var">as_arg_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969564"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969564"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680969563"><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969563"><span class="hs-keyword hs-var">as</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ArgSpec] -&gt; Expr Id
</span><a href="#local-6989586621680969569"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969563"><span class="hs-keyword hs-var">as</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Expr Id -&gt; Expr Id
forall b. Expr b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#App"><span class="hs-operator hs-var">`App`</span></a></span><span> </span><span class="annot"><span class="annottext">OutType -&gt; Expr Id
forall b. OutType -&gt; Expr b
</span><a href="GHC.Core.html#Type"><span class="hs-identifier hs-var">Type</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969564"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-361"></span><span>    </span><span class="annot"><a href="#local-6989586621680969569"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastBy"><span class="hs-identifier hs-type">CastBy</span></a></span><span> </span><span id="local-6989586621680969562"><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969562"><span class="hs-identifier hs-var">co</span></a></span></span><span>                </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680969561"><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969561"><span class="hs-keyword hs-var">as</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; OutCoercion -&gt; Expr Id
</span><a href="GHC.Core.Utils.html#mkCast"><span class="hs-identifier hs-var">mkCast</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[ArgSpec] -&gt; Expr Id
</span><a href="#local-6989586621680969569"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSpec]
</span><a href="#local-6989586621680969561"><span class="hs-keyword hs-var">as</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969562"><span class="hs-identifier hs-var">co</span></a></span><span>
</span><span id="line-362"></span><span>
</span><span id="line-363"></span><span>
</span><span id="line-364"></span><span class="hs-keyword">type</span><span> </span><span id="FunRules"><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#FunRules"><span class="hs-identifier hs-var">FunRules</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- Remaining rules for this function</span><span>
</span><span id="line-365"></span><span>     </span><span class="hs-comment">-- Nothing =&gt; No rules</span><span>
</span><span id="line-366"></span><span>     </span><span class="hs-comment">-- Just (n, rules) =&gt; some rules, requiring at least n more type/value args</span><span>
</span><span id="line-367"></span><span>
</span><span id="line-368"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#decRules"><span class="hs-identifier hs-type">decRules</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#FunRules"><span class="hs-identifier hs-type">FunRules</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#FunRules"><span class="hs-identifier hs-type">FunRules</span></a></span><span>
</span><span id="line-369"></span><span id="decRules"><span class="annot"><span class="annottext">decRules :: FunRules -&gt; FunRules
</span><a href="GHC.Core.Opt.Simplify.Utils.html#decRules"><span class="hs-identifier hs-var hs-var">decRules</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680969559"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969559"><span class="hs-identifier hs-var">n</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969558"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680969558"><span class="hs-identifier hs-var">rules</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Arity, [CoreRule]) -&gt; FunRules
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969559"><span class="hs-identifier hs-var">n</span></a></span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Arity
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">1</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680969558"><span class="hs-identifier hs-var">rules</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-370"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#decRules"><span class="hs-identifier hs-var">decRules</span></a></span><span> </span><span class="annot"><span class="annottext">FunRules
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FunRules
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-371"></span><span>
</span><span id="line-372"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkFunRules"><span class="hs-identifier hs-type">mkFunRules</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#FunRules"><span class="hs-identifier hs-type">FunRules</span></a></span><span>
</span><span id="line-373"></span><span id="mkFunRules"><span class="annot"><span class="annottext">mkFunRules :: [CoreRule] -&gt; FunRules
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkFunRules"><span class="hs-identifier hs-var hs-var">mkFunRules</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FunRules
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-374"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkFunRules"><span class="hs-identifier hs-var">mkFunRules</span></a></span><span> </span><span id="local-6989586621680969556"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680969556"><span class="hs-identifier hs-var">rs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Arity, [CoreRule]) -&gt; FunRules
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969555"><span class="hs-identifier hs-var">n_required</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680969556"><span class="hs-identifier hs-var">rs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-375"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-376"></span><span>    </span><span id="local-6989586621680969555"><span class="annot"><span class="annottext">n_required :: Arity
</span><a href="#local-6989586621680969555"><span class="hs-identifier hs-var hs-var">n_required</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Arity] -&gt; Arity
forall (t :: * -&gt; *) a. (Foldable t, Ord a) =&gt; t a -&gt; a
</span><a href="../../base/src/Data.Foldable.html#maximum"><span class="hs-identifier hs-var">maximum</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(CoreRule -&gt; Arity) -&gt; [CoreRule] -&gt; [Arity]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule -&gt; Arity
</span><a href="GHC.Core.html#ruleArity"><span class="hs-identifier hs-var">ruleArity</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680969556"><span class="hs-identifier hs-var">rs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-377"></span><span>
</span><span id="line-378"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
                Functions on SimplCont
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-385"></span><span>
</span><span id="line-386"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkBoringStop"><span class="hs-identifier hs-type">mkBoringStop</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span>
</span><span id="line-387"></span><span id="mkBoringStop"><span class="annot"><span class="annottext">mkBoringStop :: OutType -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkBoringStop"><span class="hs-identifier hs-var hs-var">mkBoringStop</span></a></span></span><span> </span><span id="local-6989586621680969550"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969550"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType -&gt; CallCtxt -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-var">Stop</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969550"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#BoringCtxt"><span class="hs-identifier hs-var">BoringCtxt</span></a></span><span>
</span><span id="line-388"></span><span>
</span><span id="line-389"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkRhsStop"><span class="hs-identifier hs-type">mkRhsStop</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span>       </span><span class="hs-comment">-- See Note [RHS of lets] in GHC.Core.Unfold</span><span>
</span><span id="line-390"></span><span id="mkRhsStop"><span class="annot"><span class="annottext">mkRhsStop :: OutType -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkRhsStop"><span class="hs-identifier hs-var hs-var">mkRhsStop</span></a></span></span><span> </span><span id="local-6989586621680969548"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969548"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType -&gt; CallCtxt -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-var">Stop</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969548"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#RhsCtxt"><span class="hs-identifier hs-var">RhsCtxt</span></a></span><span>
</span><span id="line-391"></span><span>
</span><span id="line-392"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkLazyArgStop"><span class="hs-identifier hs-type">mkLazyArgStop</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#CallCtxt"><span class="hs-identifier hs-type">CallCtxt</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span>
</span><span id="line-393"></span><span id="mkLazyArgStop"><span class="annot"><span class="annottext">mkLazyArgStop :: OutType -&gt; CallCtxt -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkLazyArgStop"><span class="hs-identifier hs-var hs-var">mkLazyArgStop</span></a></span></span><span> </span><span id="local-6989586621680969546"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969546"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span id="local-6989586621680969545"><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680969545"><span class="hs-identifier hs-var">cci</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType -&gt; CallCtxt -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-var">Stop</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969546"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680969545"><span class="hs-identifier hs-var">cci</span></a></span><span>
</span><span id="line-394"></span><span>
</span><span id="line-395"></span><span class="hs-comment">-------------------</span><span>
</span><span id="line-396"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsRhsOrArg"><span class="hs-identifier hs-type">contIsRhsOrArg</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-397"></span><span id="contIsRhsOrArg"><span class="annot"><span class="annottext">contIsRhsOrArg :: SimplCont -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contIsRhsOrArg"><span class="hs-identifier hs-var hs-var">contIsRhsOrArg</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-type">Stop</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-398"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsRhsOrArg"><span class="hs-identifier hs-var">contIsRhsOrArg</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictBind"><span class="hs-identifier hs-type">StrictBind</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-399"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsRhsOrArg"><span class="hs-identifier hs-var">contIsRhsOrArg</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictArg"><span class="hs-identifier hs-type">StrictArg</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-400"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsRhsOrArg"><span class="hs-identifier hs-var">contIsRhsOrArg</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><span class="hs-identifier">_</span></span><span>               </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-401"></span><span>
</span><span id="line-402"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsRhs"><span class="hs-identifier hs-type">contIsRhs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-403"></span><span id="contIsRhs"><span class="annot"><span class="annottext">contIsRhs :: SimplCont -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contIsRhs"><span class="hs-identifier hs-var hs-var">contIsRhs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-type">Stop</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#RhsCtxt"><span class="hs-identifier hs-var">RhsCtxt</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-404"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsRhs"><span class="hs-identifier hs-var">contIsRhs</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><span class="hs-identifier">_</span></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-405"></span><span>
</span><span id="line-406"></span><span class="hs-comment">-------------------</span><span>
</span><span id="line-407"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsStop"><span class="hs-identifier hs-type">contIsStop</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-408"></span><span id="contIsStop"><span class="annot"><span class="annottext">contIsStop :: SimplCont -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contIsStop"><span class="hs-identifier hs-var hs-var">contIsStop</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-type">Stop</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-409"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsStop"><span class="hs-identifier hs-var">contIsStop</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><span class="hs-identifier">_</span></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-410"></span><span>
</span><span id="line-411"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsDupable"><span class="hs-identifier hs-type">contIsDupable</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-412"></span><span id="contIsDupable"><span class="annot"><span class="annottext">contIsDupable :: SimplCont -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contIsDupable"><span class="hs-identifier hs-var hs-var">contIsDupable</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-type">Stop</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>                         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-413"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsDupable"><span class="hs-identifier hs-var">contIsDupable</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToTy"><span class="hs-identifier hs-type">ApplyToTy</span></a></span><span>  </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969543"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969543"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contIsDupable"><span class="hs-identifier hs-var">contIsDupable</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969543"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-414"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsDupable"><span class="hs-identifier hs-var">contIsDupable</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToVal"><span class="hs-identifier hs-type">ApplyToVal</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_dup :: SimplCont -&gt; DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_dup"><span class="hs-identifier hs-var">sc_dup</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#OkToDup"><span class="hs-identifier hs-var">OkToDup</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="hs-comment">-- See Note [DupFlag invariants]</span><span>
</span><span id="line-415"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsDupable"><span class="hs-identifier hs-var">contIsDupable</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Select"><span class="hs-identifier hs-type">Select</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_dup :: SimplCont -&gt; DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_dup"><span class="hs-identifier hs-var">sc_dup</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#OkToDup"><span class="hs-identifier hs-var">OkToDup</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="hs-comment">-- ...ditto...</span><span>
</span><span id="line-416"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsDupable"><span class="hs-identifier hs-var">contIsDupable</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictArg"><span class="hs-identifier hs-type">StrictArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_dup :: SimplCont -&gt; DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_dup"><span class="hs-identifier hs-var">sc_dup</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#OkToDup"><span class="hs-identifier hs-var">OkToDup</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="hs-comment">-- ...ditto...</span><span>
</span><span id="line-417"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsDupable"><span class="hs-identifier hs-var">contIsDupable</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastIt"><span class="hs-identifier hs-type">CastIt</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969542"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969542"><span class="hs-identifier hs-var">k</span></a></span></span><span class="hs-special">)</span><span>                      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contIsDupable"><span class="hs-identifier hs-var">contIsDupable</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969542"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-418"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsDupable"><span class="hs-identifier hs-var">contIsDupable</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><span class="hs-identifier">_</span></span><span>                                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-419"></span><span>
</span><span id="line-420"></span><span class="hs-comment">-------------------</span><span>
</span><span id="line-421"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsTrivial"><span class="hs-identifier hs-type">contIsTrivial</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-422"></span><span id="contIsTrivial"><span class="annot"><span class="annottext">contIsTrivial :: SimplCont -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contIsTrivial"><span class="hs-identifier hs-var hs-var">contIsTrivial</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-type">Stop</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>                                         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-423"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsTrivial"><span class="hs-identifier hs-var">contIsTrivial</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToTy"><span class="hs-identifier hs-type">ApplyToTy</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969541"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969541"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>                       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contIsTrivial"><span class="hs-identifier hs-var">contIsTrivial</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969541"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-424"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsTrivial"><span class="hs-identifier hs-var">contIsTrivial</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToVal"><span class="hs-identifier hs-type">ApplyToVal</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_arg :: SimplCont -&gt; Expr Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_arg"><span class="hs-identifier hs-var">sc_arg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Core.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969539"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969539"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contIsTrivial"><span class="hs-identifier hs-var">contIsTrivial</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969539"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-425"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsTrivial"><span class="hs-identifier hs-var">contIsTrivial</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastIt"><span class="hs-identifier hs-type">CastIt</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969538"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969538"><span class="hs-identifier hs-var">k</span></a></span></span><span class="hs-special">)</span><span>                                      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contIsTrivial"><span class="hs-identifier hs-var">contIsTrivial</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969538"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-426"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contIsTrivial"><span class="hs-identifier hs-var">contIsTrivial</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><span class="hs-identifier">_</span></span><span>                                                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-427"></span><span>
</span><span id="line-428"></span><span class="hs-comment">-------------------</span><span>
</span><span id="line-429"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-type">contResultType</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span>
</span><span id="line-430"></span><span id="contResultType"><span class="annot"><span class="annottext">contResultType :: SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var hs-var">contResultType</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-type">Stop</span></a></span><span> </span><span id="local-6989586621680969537"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969537"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>                  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969537"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-431"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var">contResultType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastIt"><span class="hs-identifier hs-type">CastIt</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969536"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969536"><span class="hs-identifier hs-var">k</span></a></span></span><span class="hs-special">)</span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var">contResultType</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969536"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-432"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var">contResultType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictBind"><span class="hs-identifier hs-type">StrictBind</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969535"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969535"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var">contResultType</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969535"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-433"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var">contResultType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictArg"><span class="hs-identifier hs-type">StrictArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969534"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969534"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var">contResultType</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969534"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-434"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var">contResultType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Select"><span class="hs-identifier hs-type">Select</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969533"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969533"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var">contResultType</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969533"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-435"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var">contResultType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToTy"><span class="hs-identifier hs-type">ApplyToTy</span></a></span><span>  </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969532"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969532"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var">contResultType</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969532"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-436"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var">contResultType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToVal"><span class="hs-identifier hs-type">ApplyToVal</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969531"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969531"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var">contResultType</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969531"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-437"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var">contResultType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#TickIt"><span class="hs-identifier hs-type">TickIt</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969530"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969530"><span class="hs-identifier hs-var">k</span></a></span></span><span class="hs-special">)</span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contResultType"><span class="hs-identifier hs-var">contResultType</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969530"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-438"></span><span>
</span><span id="line-439"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleType"><span class="hs-identifier hs-type">contHoleType</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span>
</span><span id="line-440"></span><span id="contHoleType"><span class="annot"><span class="annottext">contHoleType :: SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleType"><span class="hs-identifier hs-var hs-var">contHoleType</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-type">Stop</span></a></span><span> </span><span id="local-6989586621680969529"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969529"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>                      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969529"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-441"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleType"><span class="hs-identifier hs-var">contHoleType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#TickIt"><span class="hs-identifier hs-type">TickIt</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969528"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969528"><span class="hs-identifier hs-var">k</span></a></span></span><span class="hs-special">)</span><span>                     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleType"><span class="hs-identifier hs-var">contHoleType</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969528"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-442"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleType"><span class="hs-identifier hs-var">contHoleType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastIt"><span class="hs-identifier hs-type">CastIt</span></a></span><span> </span><span id="local-6989586621680969527"><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969527"><span class="hs-identifier hs-var">co</span></a></span></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>                    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutCoercion -&gt; OutType
</span><a href="GHC.Core.Coercion.html#coercionLKind"><span class="hs-identifier hs-var">coercionLKind</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969527"><span class="hs-identifier hs-var">co</span></a></span><span>
</span><span id="line-443"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleType"><span class="hs-identifier hs-var">contHoleType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictBind"><span class="hs-identifier hs-type">StrictBind</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_bndr :: SimplCont -&gt; Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_bndr"><span class="hs-identifier hs-var">sc_bndr</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969525"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969525"><span class="hs-identifier hs-var">b</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_dup :: SimplCont -&gt; DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_dup"><span class="hs-identifier hs-var">sc_dup</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969524"><span class="annot"><span class="annottext">DupFlag
</span><a href="#local-6989586621680969524"><span class="hs-identifier hs-var">dup</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_env :: SimplCont -&gt; StaticEnv
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_env"><span class="hs-identifier hs-var">sc_env</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969523"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969523"><span class="hs-identifier hs-var">se</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-444"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DupFlag -&gt; StaticEnv -&gt; OutType -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#perhapsSubstTy"><span class="hs-identifier hs-var">perhapsSubstTy</span></a></span><span> </span><span class="annot"><span class="annottext">DupFlag
</span><a href="#local-6989586621680969524"><span class="hs-identifier hs-var">dup</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969523"><span class="hs-identifier hs-var">se</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OutType
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969525"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-445"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleType"><span class="hs-identifier hs-var">contHoleType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictArg"><span class="hs-identifier hs-type">StrictArg</span></a></span><span>  </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_fun_ty :: SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_fun_ty"><span class="hs-identifier hs-var">sc_fun_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969521"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969521"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType -&gt; OutType
</span><a href="GHC.Core.Type.html#funArgTy"><span class="hs-identifier hs-var">funArgTy</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969521"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-446"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleType"><span class="hs-identifier hs-var">contHoleType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToTy"><span class="hs-identifier hs-type">ApplyToTy</span></a></span><span>  </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_hole_ty :: SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_hole_ty"><span class="hs-identifier hs-var">sc_hole_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969519"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969519"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969519"><span class="hs-identifier hs-var">ty</span></a></span><span>  </span><span class="hs-comment">-- See Note [The hole type in ApplyToTy]</span><span>
</span><span id="line-447"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleType"><span class="hs-identifier hs-var">contHoleType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToVal"><span class="hs-identifier hs-type">ApplyToVal</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_hole_ty :: SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_hole_ty"><span class="hs-identifier hs-var">sc_hole_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969518"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969518"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969518"><span class="hs-identifier hs-var">ty</span></a></span><span>  </span><span class="hs-comment">-- See Note [The hole type in ApplyToTy/Val]</span><span>
</span><span id="line-448"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleType"><span class="hs-identifier hs-var">contHoleType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Select"><span class="hs-identifier hs-type">Select</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_dup :: SimplCont -&gt; DupFlag
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_dup"><span class="hs-identifier hs-var">sc_dup</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969517"><span class="annot"><span class="annottext">DupFlag
</span><a href="#local-6989586621680969517"><span class="hs-identifier hs-var">d</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_bndr :: SimplCont -&gt; Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_bndr"><span class="hs-identifier hs-var">sc_bndr</span></a></span><span> </span><span class="hs-glyph">=</span><span>  </span><span id="local-6989586621680969516"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969516"><span class="hs-identifier hs-var">b</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_env :: SimplCont -&gt; StaticEnv
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_env"><span class="hs-identifier hs-var">sc_env</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969515"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969515"><span class="hs-identifier hs-var">se</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-449"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DupFlag -&gt; StaticEnv -&gt; OutType -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#perhapsSubstTy"><span class="hs-identifier hs-var">perhapsSubstTy</span></a></span><span> </span><span class="annot"><span class="annottext">DupFlag
</span><a href="#local-6989586621680969517"><span class="hs-identifier hs-var">d</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969515"><span class="hs-identifier hs-var">se</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OutType
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969516"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-450"></span><span>
</span><span id="line-451"></span><span>
</span><span id="line-452"></span><span class="hs-comment">-- Computes the multiplicity scaling factor at the hole. That is, in (case [] of</span><span>
</span><span id="line-453"></span><span class="hs-comment">-- x ::(p) _ { &#8230; }) (respectively for arguments of functions), the scaling</span><span>
</span><span id="line-454"></span><span class="hs-comment">-- factor is p. And in E[G[]], the scaling factor is the product of the scaling</span><span>
</span><span id="line-455"></span><span class="hs-comment">-- factor of E and that of G.</span><span>
</span><span id="line-456"></span><span class="hs-comment">--</span><span>
</span><span id="line-457"></span><span class="hs-comment">-- The scaling factor at the hole of E[] is used to determine how a binder</span><span>
</span><span id="line-458"></span><span class="hs-comment">-- should be scaled if it commutes with E. This appears, in particular, in the</span><span>
</span><span id="line-459"></span><span class="hs-comment">-- case-of-case transformation.</span><span>
</span><span id="line-460"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-type">contHoleScaling</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Mult"><span class="hs-identifier hs-type">Mult</span></a></span><span>
</span><span id="line-461"></span><span id="contHoleScaling"><span class="annot"><span class="annottext">contHoleScaling :: SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var hs-var">contHoleScaling</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-type">Stop</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="GHC.Core.Type.html#One"><span class="hs-identifier hs-var">One</span></a></span><span>
</span><span id="line-462"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var">contHoleScaling</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastIt"><span class="hs-identifier hs-type">CastIt</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969512"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969512"><span class="hs-identifier hs-var">k</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var">contHoleScaling</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969512"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-463"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var">contHoleScaling</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictBind"><span class="hs-identifier hs-type">StrictBind</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_bndr :: SimplCont -&gt; Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_bndr"><span class="hs-identifier hs-var">sc_bndr</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969511"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969511"><span class="hs-identifier hs-var">id</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969510"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969510"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-464"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; OutType
</span><a href="GHC.Types.Id.html#idMult"><span class="hs-identifier hs-var">idMult</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969511"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">OutType -&gt; OutType -&gt; OutType
</span><a href="GHC.Core.Multiplicity.html#mkMultMul"><span class="hs-operator hs-var">`mkMultMul`</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var">contHoleScaling</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969510"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-465"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var">contHoleScaling</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Select"><span class="hs-identifier hs-type">Select</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_bndr :: SimplCont -&gt; Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_bndr"><span class="hs-identifier hs-var">sc_bndr</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969507"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969507"><span class="hs-identifier hs-var">id</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969506"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969506"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-466"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; OutType
</span><a href="GHC.Types.Id.html#idMult"><span class="hs-identifier hs-var">idMult</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969507"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">OutType -&gt; OutType -&gt; OutType
</span><a href="GHC.Core.Multiplicity.html#mkMultMul"><span class="hs-operator hs-var">`mkMultMul`</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var">contHoleScaling</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969506"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-467"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var">contHoleScaling</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictArg"><span class="hs-identifier hs-type">StrictArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_fun_ty :: SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_fun_ty"><span class="hs-identifier hs-var">sc_fun_ty</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969505"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969505"><span class="hs-identifier hs-var">fun_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969504"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969504"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-468"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969503"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">OutType -&gt; OutType -&gt; OutType
</span><a href="GHC.Core.Multiplicity.html#mkMultMul"><span class="hs-operator hs-var">`mkMultMul`</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var">contHoleScaling</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969504"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-469"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-470"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680969503"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969503"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">OutType
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">OutType
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType -&gt; (OutType, OutType, OutType)
</span><a href="GHC.Core.Type.html#splitFunTy"><span class="hs-identifier hs-var">splitFunTy</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969505"><span class="hs-identifier hs-var">fun_ty</span></a></span><span>
</span><span id="line-471"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var">contHoleScaling</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToTy"><span class="hs-identifier hs-type">ApplyToTy</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969501"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969501"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var">contHoleScaling</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969501"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-472"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var">contHoleScaling</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToVal"><span class="hs-identifier hs-type">ApplyToVal</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969500"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969500"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var">contHoleScaling</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969500"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-473"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var">contHoleScaling</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#TickIt"><span class="hs-identifier hs-type">TickIt</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969499"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969499"><span class="hs-identifier hs-var">k</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; OutType
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contHoleScaling"><span class="hs-identifier hs-var">contHoleScaling</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969499"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-474"></span><span class="hs-comment">-------------------</span><span>
</span><span id="line-475"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#countArgs"><span class="hs-identifier hs-type">countArgs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-476"></span><span class="hs-comment">-- Count all arguments, including types, coercions, and other values</span><span>
</span><span id="line-477"></span><span id="countArgs"><span class="annot"><span class="annottext">countArgs :: SimplCont -&gt; Arity
</span><a href="GHC.Core.Opt.Simplify.Utils.html#countArgs"><span class="hs-identifier hs-var hs-var">countArgs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToTy"><span class="hs-identifier hs-type">ApplyToTy</span></a></span><span>  </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969498"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969498"><span class="hs-identifier hs-var">cont</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Arity
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; Arity
</span><a href="GHC.Core.Opt.Simplify.Utils.html#countArgs"><span class="hs-identifier hs-var">countArgs</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969498"><span class="hs-identifier hs-var">cont</span></a></span><span>
</span><span id="line-478"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#countArgs"><span class="hs-identifier hs-var">countArgs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToVal"><span class="hs-identifier hs-type">ApplyToVal</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969496"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969496"><span class="hs-identifier hs-var">cont</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Arity
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; Arity
</span><a href="GHC.Core.Opt.Simplify.Utils.html#countArgs"><span class="hs-identifier hs-var">countArgs</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969496"><span class="hs-identifier hs-var">cont</span></a></span><span>
</span><span id="line-479"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#countArgs"><span class="hs-identifier hs-var">countArgs</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><span class="hs-identifier">_</span></span><span>                               </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">0</span></span><span>
</span><span id="line-480"></span><span>
</span><span id="line-481"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#contArgs"><span class="hs-identifier hs-type">contArgs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Unfold.html#ArgSummary"><span class="hs-identifier hs-type">ArgSummary</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-482"></span><span class="hs-comment">-- Summarises value args, discards type args and coercions</span><span>
</span><span id="line-483"></span><span class="hs-comment">-- The returned continuation of the call is only used to</span><span>
</span><span id="line-484"></span><span class="hs-comment">-- answer questions like &quot;are you interesting?&quot;</span><span>
</span><span id="line-485"></span><span id="contArgs"><span class="annot"><span class="annottext">contArgs :: SimplCont -&gt; (Bool, [ArgSummary], SimplCont)
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contArgs"><span class="hs-identifier hs-var hs-var">contArgs</span></a></span></span><span> </span><span id="local-6989586621680969495"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969495"><span class="hs-identifier hs-var">cont</span></a></span></span><span>
</span><span id="line-486"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; Bool
</span><a href="#local-6989586621680969494"><span class="hs-identifier hs-var">lone</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969495"><span class="hs-identifier hs-var">cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969495"><span class="hs-identifier hs-var">cont</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-487"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ArgSummary] -&gt; SimplCont -&gt; (Bool, [ArgSummary], SimplCont)
</span><a href="#local-6989586621680969493"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969495"><span class="hs-identifier hs-var">cont</span></a></span><span>
</span><span id="line-488"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-489"></span><span>    </span><span id="local-6989586621680969494"><span class="annot"><span class="annottext">lone :: SimplCont -&gt; Bool
</span><a href="#local-6989586621680969494"><span class="hs-identifier hs-var hs-var">lone</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToTy"><span class="hs-identifier hs-type">ApplyToTy</span></a></span><span>  </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>  </span><span class="hs-comment">-- See Note [Lone variables] in GHC.Core.Unfold</span><span>
</span><span id="line-490"></span><span>    </span><span class="annot"><a href="#local-6989586621680969494"><span class="hs-identifier hs-var">lone</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToVal"><span class="hs-identifier hs-type">ApplyToVal</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>  </span><span class="hs-comment">-- NB: even a type application or cast</span><span>
</span><span id="line-491"></span><span>    </span><span class="annot"><a href="#local-6989586621680969494"><span class="hs-identifier hs-var">lone</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastIt"><span class="hs-identifier hs-type">CastIt</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>  </span><span class="hs-comment">--     stops it being &quot;lone&quot;</span><span>
</span><span id="line-492"></span><span>    </span><span class="annot"><a href="#local-6989586621680969494"><span class="hs-identifier hs-var">lone</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><span class="hs-identifier">_</span></span><span>               </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-493"></span><span>
</span><span id="line-494"></span><span>    </span><span id="local-6989586621680969493"><span class="annot"><span class="annottext">go :: [ArgSummary] -&gt; SimplCont -&gt; (Bool, [ArgSummary], SimplCont)
</span><a href="#local-6989586621680969493"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621680969492"><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680969492"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToVal"><span class="hs-identifier hs-type">ApplyToVal</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_arg :: SimplCont -&gt; Expr Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_arg"><span class="hs-identifier hs-var">sc_arg</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969491"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969491"><span class="hs-identifier hs-var">arg</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_env :: SimplCont -&gt; StaticEnv
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_env"><span class="hs-identifier hs-var">sc_env</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969490"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969490"><span class="hs-identifier hs-var">se</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969489"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969489"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-495"></span><span>                                        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ArgSummary] -&gt; SimplCont -&gt; (Bool, [ArgSummary], SimplCont)
</span><a href="#local-6989586621680969493"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Expr Id -&gt; StaticEnv -&gt; ArgSummary
</span><a href="#local-6989586621680969488"><span class="hs-identifier hs-var">is_interesting</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969491"><span class="hs-identifier hs-var">arg</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969490"><span class="hs-identifier hs-var">se</span></a></span><span> </span><span class="annot"><span class="annottext">ArgSummary -&gt; [ArgSummary] -&gt; [ArgSummary]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680969492"><span class="hs-identifier hs-var">args</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969489"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-496"></span><span>    </span><span class="annot"><a href="#local-6989586621680969493"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680969487"><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680969487"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToTy"><span class="hs-identifier hs-type">ApplyToTy</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969486"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969486"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ArgSummary] -&gt; SimplCont -&gt; (Bool, [ArgSummary], SimplCont)
</span><a href="#local-6989586621680969493"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680969487"><span class="hs-identifier hs-var">args</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969486"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-497"></span><span>    </span><span class="annot"><a href="#local-6989586621680969493"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680969485"><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680969485"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastIt"><span class="hs-identifier hs-type">CastIt</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969484"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969484"><span class="hs-identifier hs-var">k</span></a></span></span><span class="hs-special">)</span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ArgSummary] -&gt; SimplCont -&gt; (Bool, [ArgSummary], SimplCont)
</span><a href="#local-6989586621680969493"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680969485"><span class="hs-identifier hs-var">args</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969484"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-498"></span><span>    </span><span class="annot"><a href="#local-6989586621680969493"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680969483"><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680969483"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span id="local-6989586621680969482"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969482"><span class="hs-identifier hs-var">k</span></a></span></span><span>                           </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[ArgSummary] -&gt; [ArgSummary]
forall a. [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="annot"><span class="annottext">[ArgSummary]
</span><a href="#local-6989586621680969483"><span class="hs-identifier hs-var">args</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969482"><span class="hs-identifier hs-var">k</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-499"></span><span>
</span><span id="line-500"></span><span>    </span><span id="local-6989586621680969488"><span class="annot"><span class="annottext">is_interesting :: Expr Id -&gt; StaticEnv -&gt; ArgSummary
</span><a href="#local-6989586621680969488"><span class="hs-identifier hs-var hs-var">is_interesting</span></a></span></span><span> </span><span id="local-6989586621680969480"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969480"><span class="hs-identifier hs-var">arg</span></a></span></span><span> </span><span id="local-6989586621680969479"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969479"><span class="hs-identifier hs-var">se</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; Expr Id -&gt; ArgSummary
</span><a href="GHC.Core.Opt.Simplify.Utils.html#interestingArg"><span class="hs-identifier hs-var">interestingArg</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969479"><span class="hs-identifier hs-var">se</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969480"><span class="hs-identifier hs-var">arg</span></a></span><span>
</span><span id="line-501"></span><span>                   </span><span class="hs-comment">-- Do *not* use short-cutting substitution here</span><span>
</span><span id="line-502"></span><span>                   </span><span class="hs-comment">-- because we want to get as much IdInfo as possible</span><span>
</span><span id="line-503"></span><span>
</span><span id="line-504"></span><span>
</span><span id="line-505"></span><span class="hs-comment">-------------------</span><span>
</span><span id="line-506"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkArgInfo"><span class="hs-identifier hs-type">mkArgInfo</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#SimplEnv"><span class="hs-identifier hs-type">SimplEnv</span></a></span><span>
</span><span id="line-507"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span>
</span><span id="line-508"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-comment">-- Rules for function</span><span>
</span><span id="line-509"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>        </span><span class="hs-comment">-- Number of value args</span><span>
</span><span id="line-510"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span>  </span><span class="hs-comment">-- Context of the call</span><span>
</span><span id="line-511"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span>
</span><span id="line-512"></span><span>
</span><span id="line-513"></span><span id="mkArgInfo"><span class="annot"><span class="annottext">mkArgInfo :: StaticEnv -&gt; Id -&gt; [CoreRule] -&gt; Arity -&gt; SimplCont -&gt; ArgInfo
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkArgInfo"><span class="hs-identifier hs-var hs-var">mkArgInfo</span></a></span></span><span> </span><span id="local-6989586621680969477"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969477"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680969476"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969476"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621680969475"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680969475"><span class="hs-identifier hs-var">rules</span></a></span></span><span> </span><span id="local-6989586621680969474"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969474"><span class="hs-identifier hs-var">n_val_args</span></a></span></span><span> </span><span id="local-6989586621680969473"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969473"><span class="hs-identifier hs-var">call_cont</span></a></span></span><span>
</span><span id="line-514"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969474"><span class="hs-identifier hs-var">n_val_args</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;</span></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Arity
</span><a href="GHC.Types.Id.html#idArity"><span class="hs-identifier hs-var">idArity</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969476"><span class="hs-identifier hs-var">fun</span></a></span><span>            </span><span class="hs-comment">-- Note [Unsaturated functions]</span><span>
</span><span id="line-515"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgInfo :: Id
-&gt; [ArgSpec] -&gt; FunRules -&gt; Bool -&gt; [Demand] -&gt; [Arity] -&gt; ArgInfo
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ai_fun :: Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_fun"><span class="hs-identifier hs-var">ai_fun</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969476"><span class="hs-identifier hs-var">fun</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_args :: [ArgSpec]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_args"><span class="hs-identifier hs-var">ai_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-516"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_rules :: FunRules
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_rules"><span class="hs-identifier hs-var">ai_rules</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FunRules
</span><a href="#local-6989586621680969470"><span class="hs-identifier hs-var">fun_rules</span></a></span><span>
</span><span id="line-517"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_encl :: Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_encl"><span class="hs-identifier hs-var">ai_encl</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-518"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_dmds :: [Demand]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_dmds"><span class="hs-identifier hs-var">ai_dmds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969469"><span class="hs-identifier hs-var">vanilla_dmds</span></a></span><span>
</span><span id="line-519"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_discs :: [Arity]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_discs"><span class="hs-identifier hs-var">ai_discs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Arity]
</span><a href="#local-6989586621680969468"><span class="hs-identifier hs-var">vanilla_discounts</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-520"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-521"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgInfo :: Id
-&gt; [ArgSpec] -&gt; FunRules -&gt; Bool -&gt; [Demand] -&gt; [Arity] -&gt; ArgInfo
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ai_fun :: Id
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_fun"><span class="hs-identifier hs-var">ai_fun</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969476"><span class="hs-identifier hs-var">fun</span></a></span><span>
</span><span id="line-522"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_args :: [ArgSpec]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_args"><span class="hs-identifier hs-var">ai_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-523"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_rules :: FunRules
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_rules"><span class="hs-identifier hs-var">ai_rules</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FunRules
</span><a href="#local-6989586621680969470"><span class="hs-identifier hs-var">fun_rules</span></a></span><span>
</span><span id="line-524"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_encl :: Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_encl"><span class="hs-identifier hs-var">ai_encl</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[CoreRule] -&gt; SimplCont -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#interestingArgContext"><span class="hs-identifier hs-var">interestingArgContext</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680969475"><span class="hs-identifier hs-var">rules</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969473"><span class="hs-identifier hs-var">call_cont</span></a></span><span>
</span><span id="line-525"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_dmds :: [Demand]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_dmds"><span class="hs-identifier hs-var">ai_dmds</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType -&gt; [Demand] -&gt; [Demand]
</span><a href="#local-6989586621680969466"><span class="hs-identifier hs-var">add_type_strictness</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OutType
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969476"><span class="hs-identifier hs-var">fun</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969465"><span class="hs-identifier hs-var">arg_dmds</span></a></span><span>
</span><span id="line-526"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_discs :: [Arity]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_discs"><span class="hs-identifier hs-var">ai_discs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Arity]
</span><a href="#local-6989586621680969464"><span class="hs-identifier hs-var">arg_discounts</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-527"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-528"></span><span>    </span><span id="local-6989586621680969470"><span class="annot"><span class="annottext">fun_rules :: FunRules
</span><a href="#local-6989586621680969470"><span class="hs-identifier hs-var hs-var">fun_rules</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[CoreRule] -&gt; FunRules
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkFunRules"><span class="hs-identifier hs-var">mkFunRules</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680969475"><span class="hs-identifier hs-var">rules</span></a></span><span>
</span><span id="line-529"></span><span>
</span><span id="line-530"></span><span>    </span><span class="annot"><a href="#local-6989586621680969468"><span class="hs-identifier hs-type">vanilla_discounts</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621680969464"><span class="hs-identifier hs-type">arg_discounts</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">]</span><span>
</span><span id="line-531"></span><span>    </span><span id="local-6989586621680969468"><span class="annot"><span class="annottext">vanilla_discounts :: [Arity]
</span><a href="#local-6989586621680969468"><span class="hs-identifier hs-var hs-var">vanilla_discounts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; [Arity]
forall a. a -&gt; [a]
</span><a href="../../base/src/GHC.List.html#repeat"><span class="hs-identifier hs-var">repeat</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">0</span></span><span>
</span><span id="line-532"></span><span>    </span><span id="local-6989586621680969464"><span class="annot"><span class="annottext">arg_discounts :: [Arity]
</span><a href="#local-6989586621680969464"><span class="hs-identifier hs-var hs-var">arg_discounts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Unfolding
</span><a href="GHC.Types.Id.html#idUnfolding"><span class="hs-identifier hs-var">idUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969476"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-533"></span><span>                        </span><span class="annot"><a href="GHC.Core.html#CoreUnfolding"><span class="hs-identifier hs-type">CoreUnfolding</span></a></span><span> </span><span class="hs-special">{</span><span class="annot"><span class="annottext">uf_guidance :: Unfolding -&gt; UnfoldingGuidance
</span><a href="GHC.Core.html#uf_guidance"><span class="hs-identifier hs-var">uf_guidance</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Core.html#UnfIfGoodArgs"><span class="hs-identifier hs-type">UnfIfGoodArgs</span></a></span><span> </span><span class="hs-special">{</span><span class="annot"><span class="annottext">ug_args :: UnfoldingGuidance -&gt; [Arity]
</span><a href="GHC.Core.html#ug_args"><span class="hs-identifier hs-var">ug_args</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969457"><span class="annot"><span class="annottext">[Arity]
</span><a href="#local-6989586621680969457"><span class="hs-identifier hs-var">discounts</span></a></span></span><span class="hs-special">}</span><span class="hs-special">}</span><span>
</span><span id="line-534"></span><span>                              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[Arity]
</span><a href="#local-6989586621680969457"><span class="hs-identifier hs-var">discounts</span></a></span><span> </span><span class="annot"><span class="annottext">[Arity] -&gt; [Arity] -&gt; [Arity]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[Arity]
</span><a href="#local-6989586621680969468"><span class="hs-identifier hs-var">vanilla_discounts</span></a></span><span>
</span><span id="line-535"></span><span>                        </span><span class="annot"><span class="annottext">Unfolding
</span><span class="hs-identifier">_</span></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[Arity]
</span><a href="#local-6989586621680969468"><span class="hs-identifier hs-var">vanilla_discounts</span></a></span><span>
</span><span id="line-536"></span><span>
</span><span id="line-537"></span><span>    </span><span class="annot"><a href="#local-6989586621680969469"><span class="hs-identifier hs-type">vanilla_dmds</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621680969465"><span class="hs-identifier hs-type">arg_dmds</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Demand.html#Demand"><span class="hs-identifier hs-type">Demand</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-538"></span><span>    </span><span id="local-6989586621680969469"><span class="annot"><span class="annottext">vanilla_dmds :: [Demand]
</span><a href="#local-6989586621680969469"><span class="hs-identifier hs-var hs-var">vanilla_dmds</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Demand -&gt; [Demand]
forall a. a -&gt; [a]
</span><a href="../../base/src/GHC.List.html#repeat"><span class="hs-identifier hs-var">repeat</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="GHC.Types.Demand.html#topDmd"><span class="hs-identifier hs-var">topDmd</span></a></span><span>
</span><span id="line-539"></span><span>
</span><span id="line-540"></span><span>    </span><span id="local-6989586621680969465"><span class="annot"><span class="annottext">arg_dmds :: [Demand]
</span><a href="#local-6989586621680969465"><span class="hs-identifier hs-var hs-var">arg_dmds</span></a></span></span><span>
</span><span id="line-541"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SimplMode -&gt; Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_inline"><span class="hs-identifier hs-var hs-var">sm_inline</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StaticEnv -&gt; SimplMode
</span><a href="GHC.Core.Opt.Simplify.Env.html#seMode"><span class="hs-identifier hs-var hs-var">seMode</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969477"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-542"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969469"><span class="hs-identifier hs-var">vanilla_dmds</span></a></span><span> </span><span class="hs-comment">-- See Note [Do not expose strictness if sm_inline=False]</span><span>
</span><span id="line-543"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-544"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-comment">-- add_type_str fun_ty $</span><span>
</span><span id="line-545"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">StrictSig -&gt; ([Demand], Divergence)
</span><a href="GHC.Types.Demand.html#splitStrictSig"><span class="hs-identifier hs-var">splitStrictSig</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; StrictSig
</span><a href="GHC.Types.Id.html#idStrictness"><span class="hs-identifier hs-var">idStrictness</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969476"><span class="hs-identifier hs-var">fun</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-546"></span><span>          </span><span class="hs-special">(</span><span id="local-6989586621680969450"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969450"><span class="hs-identifier hs-var">demands</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969449"><span class="annot"><span class="annottext">Divergence
</span><a href="#local-6989586621680969449"><span class="hs-identifier hs-var">result_info</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-547"></span><span>                </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969450"><span class="hs-identifier hs-var">demands</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand] -&gt; Arity -&gt; Bool
forall a. [a] -&gt; Arity -&gt; Bool
</span><a href="GHC.Utils.Misc.html#lengthExceeds"><span class="hs-operator hs-var">`lengthExceeds`</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969474"><span class="hs-identifier hs-var">n_val_args</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-548"></span><span>                </span><span class="hs-glyph">-&gt;</span><span>      </span><span class="hs-comment">-- Enough args, use the strictness given.</span><span>
</span><span id="line-549"></span><span>                        </span><span class="hs-comment">-- For bottoming functions we used to pretend that the arg</span><span>
</span><span id="line-550"></span><span>                        </span><span class="hs-comment">-- is lazy, so that we don't treat the arg as an</span><span>
</span><span id="line-551"></span><span>                        </span><span class="hs-comment">-- interesting context.  This avoids substituting</span><span>
</span><span id="line-552"></span><span>                        </span><span class="hs-comment">-- top-level bindings for (say) strings into</span><span>
</span><span id="line-553"></span><span>                        </span><span class="hs-comment">-- calls to error.  But now we are more careful about</span><span>
</span><span id="line-554"></span><span>                        </span><span class="hs-comment">-- inlining lone variables, so its ok</span><span>
</span><span id="line-555"></span><span>                        </span><span class="hs-comment">-- (see GHC.Core.Op.Simplify.Utils.analyseCont)</span><span>
</span><span id="line-556"></span><span>                   </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Divergence -&gt; Bool
</span><a href="GHC.Types.Demand.html#isDeadEndDiv"><span class="hs-identifier hs-var">isDeadEndDiv</span></a></span><span> </span><span class="annot"><span class="annottext">Divergence
</span><a href="#local-6989586621680969449"><span class="hs-identifier hs-var">result_info</span></a></span><span> </span><span class="hs-keyword">then</span><span>
</span><span id="line-557"></span><span>                        </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969450"><span class="hs-identifier hs-var">demands</span></a></span><span>  </span><span class="hs-comment">-- Finite =&gt; result is bottom</span><span>
</span><span id="line-558"></span><span>                   </span><span class="hs-keyword">else</span><span>
</span><span id="line-559"></span><span>                        </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969450"><span class="hs-identifier hs-var">demands</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand] -&gt; [Demand] -&gt; [Demand]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969469"><span class="hs-identifier hs-var">vanilla_dmds</span></a></span><span>
</span><span id="line-560"></span><span>               </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-561"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">WARN</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">True</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">text</span><span> </span><span class="hs-string">&quot;More demands than arity&quot;</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">fun</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">idArity</span><span> </span><span class="hs-identifier">fun</span><span class="hs-special">)</span><span>
</span><span id="line-562"></span><span>                                </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">n_val_args</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">demands</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-563"></span><span>                  </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969469"><span class="hs-identifier hs-var">vanilla_dmds</span></a></span><span>      </span><span class="hs-comment">-- Not enough args, or no strictness</span><span>
</span><span id="line-564"></span><span>
</span><span id="line-565"></span><span>    </span><span class="annot"><a href="#local-6989586621680969466"><span class="hs-identifier hs-type">add_type_strictness</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Demand.html#Demand"><span class="hs-identifier hs-type">Demand</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Demand.html#Demand"><span class="hs-identifier hs-type">Demand</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-566"></span><span>    </span><span class="hs-comment">-- If the function arg types are strict, record that in the 'strictness bits'</span><span>
</span><span id="line-567"></span><span>    </span><span class="hs-comment">-- No need to instantiate because unboxed types (which dominate the strict</span><span>
</span><span id="line-568"></span><span>    </span><span class="hs-comment">--   types) can't instantiate type variables.</span><span>
</span><span id="line-569"></span><span>    </span><span class="hs-comment">-- add_type_strictness is done repeatedly (for each call);</span><span>
</span><span id="line-570"></span><span>    </span><span class="hs-comment">--   might be better once-for-all in the function</span><span>
</span><span id="line-571"></span><span>    </span><span class="hs-comment">-- But beware primops/datacons with no strictness</span><span>
</span><span id="line-572"></span><span>
</span><span id="line-573"></span><span>    </span><span id="local-6989586621680969466"><span class="annot"><span class="annottext">add_type_strictness :: OutType -&gt; [Demand] -&gt; [Demand]
</span><a href="#local-6989586621680969466"><span class="hs-identifier hs-var hs-var">add_type_strictness</span></a></span></span><span> </span><span id="local-6989586621680969445"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969445"><span class="hs-identifier hs-var">fun_ty</span></a></span></span><span> </span><span id="local-6989586621680969444"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969444"><span class="hs-identifier hs-var">dmds</span></a></span></span><span>
</span><span id="line-574"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[Demand] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969444"><span class="hs-identifier hs-var">dmds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-575"></span><span>
</span><span id="line-576"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969442"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969442"><span class="hs-identifier hs-var">fun_ty'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">OutType -&gt; Maybe (Id, OutType)
</span><a href="GHC.Core.Type.html#splitForAllTy_maybe"><span class="hs-identifier hs-var">splitForAllTy_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969445"><span class="hs-identifier hs-var">fun_ty</span></a></span><span>
</span><span id="line-577"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType -&gt; [Demand] -&gt; [Demand]
</span><a href="#local-6989586621680969466"><span class="hs-identifier hs-var">add_type_strictness</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969442"><span class="hs-identifier hs-var">fun_ty'</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969444"><span class="hs-identifier hs-var">dmds</span></a></span><span>     </span><span class="hs-comment">-- Look through foralls</span><span>
</span><span id="line-578"></span><span>
</span><span id="line-579"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">OutType
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969440"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969440"><span class="hs-identifier hs-var">arg_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969439"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969439"><span class="hs-identifier hs-var">fun_ty'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">OutType -&gt; Maybe (OutType, OutType, OutType)
</span><a href="GHC.Core.Type.html#splitFunTy_maybe"><span class="hs-identifier hs-var">splitFunTy_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969445"><span class="hs-identifier hs-var">fun_ty</span></a></span><span>        </span><span class="hs-comment">-- Add strict-type info</span><span>
</span><span id="line-580"></span><span>      </span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969437"><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680969437"><span class="hs-identifier hs-var">dmd</span></a></span></span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680969436"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969436"><span class="hs-identifier hs-var">rest_dmds</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969444"><span class="hs-identifier hs-var">dmds</span></a></span><span>
</span><span id="line-581"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680969434"><span class="annot"><span class="annottext">dmd' :: Demand
</span><a href="#local-6989586621680969434"><span class="hs-identifier hs-var hs-var">dmd'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; OutType -&gt; Maybe Bool
OutType -&gt; Maybe Bool
</span><a href="GHC.Core.Type.html#isLiftedType_maybe"><span class="hs-identifier hs-var">isLiftedType_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969440"><span class="hs-identifier hs-var">arg_ty</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-582"></span><span>                       </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Demand -&gt; Demand
</span><a href="GHC.Types.Demand.html#strictenDmd"><span class="hs-identifier hs-var">strictenDmd</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680969437"><span class="hs-identifier hs-var">dmd</span></a></span><span>
</span><span id="line-583"></span><span>                       </span><span class="annot"><span class="annottext">Maybe Bool
</span><span class="hs-identifier">_</span></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680969437"><span class="hs-identifier hs-var">dmd</span></a></span><span>
</span><span id="line-584"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680969434"><span class="hs-identifier hs-var">dmd'</span></a></span><span> </span><span class="annot"><span class="annottext">Demand -&gt; [Demand] -&gt; [Demand]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">OutType -&gt; [Demand] -&gt; [Demand]
</span><a href="#local-6989586621680969466"><span class="hs-identifier hs-var">add_type_strictness</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969439"><span class="hs-identifier hs-var">fun_ty'</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969436"><span class="hs-identifier hs-var">rest_dmds</span></a></span><span>
</span><span id="line-585"></span><span>          </span><span class="hs-comment">-- If the type is levity-polymorphic, we can't know whether it's</span><span>
</span><span id="line-586"></span><span>          </span><span class="hs-comment">-- strict. isLiftedType_maybe will return Just False only when</span><span>
</span><span id="line-587"></span><span>          </span><span class="hs-comment">-- we're sure the type is unlifted.</span><span>
</span><span id="line-588"></span><span>
</span><span id="line-589"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-590"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680969444"><span class="hs-identifier hs-var">dmds</span></a></span><span>
</span><span id="line-591"></span><span>
</span><span id="line-592"></span><span class="hs-comment">{- Note [Unsaturated functions]
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider (test eyeball/inline4)
        x = a:as
        y = f x
where f has arity 2.  Then we do not want to inline 'x', because
it'll just be floated out again.  Even if f has lots of discounts
on its first argument -- it must be saturated for these to kick in

Note [Do not expose strictness if sm_inline=False]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#15163 showed a case in which we had

  {-# INLINE [1] zip #-}
  zip = undefined

  {-# RULES &quot;foo&quot; forall as bs. stream (zip as bs) = ..blah... #-}

If we expose zip's bottoming nature when simplifying the LHS of the
RULE we get
  {-# RULES &quot;foo&quot; forall as bs.
                   stream (case zip of {}) = ..blah... #-}
discarding the arguments to zip.  Usually this is fine, but on the
LHS of a rule it's not, because 'as' and 'bs' are now not bound on
the LHS.

This is a pretty pathological example, so I'm not losing sleep over
it, but the simplest solution was to check sm_inline; if it is False,
which it is on the LHS of a rule (see updModeForRules), then don't
make use of the strictness info for the function.
-}</span><span>
</span><span id="line-623"></span><span>
</span><span id="line-624"></span><span>
</span><span id="line-625"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
        Interesting arguments
*                                                                      *
************************************************************************

Note [Interesting call context]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We want to avoid inlining an expression where there can't possibly be
any gain, such as in an argument position.  Hence, if the continuation
is interesting (eg. a case scrutinee, application etc.) then we
inline, otherwise we don't.

Previously some_benefit used to return True only if the variable was
applied to some value arguments.  This didn't work:

        let x = _coerce_ (T Int) Int (I# 3) in
        case _coerce_ Int (T Int) x of
                I# y -&gt; ....

we want to inline x, but can't see that it's a constructor in a case
scrutinee position, and some_benefit is False.

Another example:

dMonadST = _/\_ t -&gt; :Monad (g1 _@_ t, g2 _@_ t, g3 _@_ t)

....  case dMonadST _@_ x0 of (a,b,c) -&gt; ....

we'd really like to inline dMonadST here, but we *don't* want to
inline if the case expression is just

        case x of y { DEFAULT -&gt; ... }

since we can just eliminate this case instead (x is in WHNF).  Similar
applies when x is bound to a lambda expression.  Hence
contIsInteresting looks for case expressions with just a single
default case.

Note [No case of case is boring]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If we see
   case f x of &lt;alts&gt;

we'd usually treat the context as interesting, to encourage 'f' to
inline.  But if case-of-case is off, it's really not so interesting
after all, because we are unlikely to be able to push the case
expression into the branches of any case in f's unfolding.  So, to
reduce unnecessary code expansion, we just make the context look boring.
This made a small compile-time perf improvement in perf/compiler/T6048,
and it looks plausible to me.
-}</span><span>
</span><span id="line-678"></span><span>
</span><span id="line-679"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#lazyArgContext"><span class="hs-identifier hs-type">lazyArgContext</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#CallCtxt"><span class="hs-identifier hs-type">CallCtxt</span></a></span><span>
</span><span id="line-680"></span><span class="hs-comment">-- Use this for lazy arguments</span><span>
</span><span id="line-681"></span><span id="lazyArgContext"><span class="annot"><span class="annottext">lazyArgContext :: ArgInfo -&gt; CallCtxt
</span><a href="GHC.Core.Opt.Simplify.Utils.html#lazyArgContext"><span class="hs-identifier hs-var hs-var">lazyArgContext</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ai_encl :: ArgInfo -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_encl"><span class="hs-identifier hs-var">ai_encl</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969431"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969431"><span class="hs-identifier hs-var">encl_rules</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_discs :: ArgInfo -&gt; [Arity]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_discs"><span class="hs-identifier hs-var">ai_discs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969430"><span class="annot"><span class="annottext">[Arity]
</span><a href="#local-6989586621680969430"><span class="hs-identifier hs-var">discs</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-682"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969431"><span class="hs-identifier hs-var">encl_rules</span></a></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#RuleArgCtxt"><span class="hs-identifier hs-var">RuleArgCtxt</span></a></span><span>
</span><span id="line-683"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680969428"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969428"><span class="hs-identifier hs-var">disc</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span class="annot"><span class="annottext">[Arity]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Arity]
</span><a href="#local-6989586621680969430"><span class="hs-identifier hs-var">discs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969428"><span class="hs-identifier hs-var">disc</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#DiscArgCtxt"><span class="hs-identifier hs-var">DiscArgCtxt</span></a></span><span>  </span><span class="hs-comment">-- Be keener here</span><span>
</span><span id="line-684"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#BoringCtxt"><span class="hs-identifier hs-var">BoringCtxt</span></a></span><span>   </span><span class="hs-comment">-- Nothing interesting</span><span>
</span><span id="line-685"></span><span>
</span><span id="line-686"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#strictArgContext"><span class="hs-identifier hs-type">strictArgContext</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#CallCtxt"><span class="hs-identifier hs-type">CallCtxt</span></a></span><span>
</span><span id="line-687"></span><span id="strictArgContext"><span class="annot"><span class="annottext">strictArgContext :: ArgInfo -&gt; CallCtxt
</span><a href="GHC.Core.Opt.Simplify.Utils.html#strictArgContext"><span class="hs-identifier hs-var hs-var">strictArgContext</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ArgInfo"><span class="hs-identifier hs-type">ArgInfo</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ai_encl :: ArgInfo -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_encl"><span class="hs-identifier hs-var">ai_encl</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969424"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969424"><span class="hs-identifier hs-var">encl_rules</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ai_discs :: ArgInfo -&gt; [Arity]
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_discs"><span class="hs-identifier hs-var">ai_discs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969423"><span class="annot"><span class="annottext">[Arity]
</span><a href="#local-6989586621680969423"><span class="hs-identifier hs-var">discs</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-688"></span><span class="hs-comment">-- Use this for strict arguments</span><span>
</span><span id="line-689"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969424"><span class="hs-identifier hs-var">encl_rules</span></a></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#RuleArgCtxt"><span class="hs-identifier hs-var">RuleArgCtxt</span></a></span><span>
</span><span id="line-690"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680969422"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969422"><span class="hs-identifier hs-var">disc</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span class="annot"><span class="annottext">[Arity]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Arity]
</span><a href="#local-6989586621680969423"><span class="hs-identifier hs-var">discs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969422"><span class="hs-identifier hs-var">disc</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#DiscArgCtxt"><span class="hs-identifier hs-var">DiscArgCtxt</span></a></span><span>  </span><span class="hs-comment">-- Be keener here</span><span>
</span><span id="line-691"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#RhsCtxt"><span class="hs-identifier hs-var">RhsCtxt</span></a></span><span>
</span><span id="line-692"></span><span>      </span><span class="hs-comment">-- Why RhsCtxt?  if we see f (g x) (h x), and f is strict, we</span><span>
</span><span id="line-693"></span><span>      </span><span class="hs-comment">-- want to be a bit more eager to inline g, because it may</span><span>
</span><span id="line-694"></span><span>      </span><span class="hs-comment">-- expose an eval (on x perhaps) that can be eliminated or</span><span>
</span><span id="line-695"></span><span>      </span><span class="hs-comment">-- shared. I saw this in nofib 'boyer2', RewriteFuns.onewayunify1</span><span>
</span><span id="line-696"></span><span>      </span><span class="hs-comment">-- It's worth an 18% improvement in allocation for this</span><span>
</span><span id="line-697"></span><span>      </span><span class="hs-comment">-- particular benchmark; 5% on 'mate' and 1.3% on 'multiplier'</span><span>
</span><span id="line-698"></span><span>
</span><span id="line-699"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#interestingCallContext"><span class="hs-identifier hs-type">interestingCallContext</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#SimplEnv"><span class="hs-identifier hs-type">SimplEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#CallCtxt"><span class="hs-identifier hs-type">CallCtxt</span></a></span><span>
</span><span id="line-700"></span><span class="hs-comment">-- See Note [Interesting call context]</span><span>
</span><span id="line-701"></span><span id="interestingCallContext"><span class="annot"><span class="annottext">interestingCallContext :: StaticEnv -&gt; SimplCont -&gt; CallCtxt
</span><a href="GHC.Core.Opt.Simplify.Utils.html#interestingCallContext"><span class="hs-identifier hs-var hs-var">interestingCallContext</span></a></span></span><span> </span><span id="local-6989586621680969421"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969421"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680969420"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969420"><span class="hs-identifier hs-var">cont</span></a></span></span><span>
</span><span id="line-702"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; CallCtxt
</span><a href="#local-6989586621680969419"><span class="hs-identifier hs-var">interesting</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969420"><span class="hs-identifier hs-var">cont</span></a></span><span>
</span><span id="line-703"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-704"></span><span>    </span><span id="local-6989586621680969419"><span class="annot"><span class="annottext">interesting :: SimplCont -&gt; CallCtxt
</span><a href="#local-6989586621680969419"><span class="hs-identifier hs-var hs-var">interesting</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Select"><span class="hs-identifier hs-type">Select</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-705"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">SimplMode -&gt; Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_case_case"><span class="hs-identifier hs-var hs-var">sm_case_case</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StaticEnv -&gt; SimplMode
</span><a href="GHC.Core.Opt.Simplify.Env.html#getMode"><span class="hs-identifier hs-var">getMode</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969421"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#CaseCtxt"><span class="hs-identifier hs-var">CaseCtxt</span></a></span><span>
</span><span id="line-706"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#BoringCtxt"><span class="hs-identifier hs-var">BoringCtxt</span></a></span><span>
</span><span id="line-707"></span><span>       </span><span class="hs-comment">-- See Note [No case of case is boring]</span><span>
</span><span id="line-708"></span><span>
</span><span id="line-709"></span><span>    </span><span class="annot"><a href="#local-6989586621680969419"><span class="hs-identifier hs-var">interesting</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToVal"><span class="hs-identifier hs-type">ApplyToVal</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#ValAppCtxt"><span class="hs-identifier hs-var">ValAppCtxt</span></a></span><span>
</span><span id="line-710"></span><span>        </span><span class="hs-comment">-- Can happen if we have (f Int |&gt; co) y</span><span>
</span><span id="line-711"></span><span>        </span><span class="hs-comment">-- If f has an INLINE prag we need to give it some</span><span>
</span><span id="line-712"></span><span>        </span><span class="hs-comment">-- motivation to inline. See Note [Cast then apply]</span><span>
</span><span id="line-713"></span><span>        </span><span class="hs-comment">-- in GHC.Core.Unfold</span><span>
</span><span id="line-714"></span><span>
</span><span id="line-715"></span><span>    </span><span class="annot"><a href="#local-6989586621680969419"><span class="hs-identifier hs-var">interesting</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictArg"><span class="hs-identifier hs-type">StrictArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_fun :: SimplCont -&gt; ArgInfo
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_fun"><span class="hs-identifier hs-var">sc_fun</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969414"><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969414"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgInfo -&gt; CallCtxt
</span><a href="GHC.Core.Opt.Simplify.Utils.html#strictArgContext"><span class="hs-identifier hs-var">strictArgContext</span></a></span><span> </span><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969414"><span class="hs-identifier hs-var">fun</span></a></span><span>
</span><span id="line-716"></span><span>    </span><span class="annot"><a href="#local-6989586621680969419"><span class="hs-identifier hs-var">interesting</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictBind"><span class="hs-identifier hs-type">StrictBind</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#BoringCtxt"><span class="hs-identifier hs-var">BoringCtxt</span></a></span><span>
</span><span id="line-717"></span><span>    </span><span class="annot"><a href="#local-6989586621680969419"><span class="hs-identifier hs-var">interesting</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-type">Stop</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969413"><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680969413"><span class="hs-identifier hs-var">cci</span></a></span></span><span class="hs-special">)</span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="#local-6989586621680969413"><span class="hs-identifier hs-var">cci</span></a></span><span>
</span><span id="line-718"></span><span>    </span><span class="annot"><a href="#local-6989586621680969419"><span class="hs-identifier hs-var">interesting</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#TickIt"><span class="hs-identifier hs-type">TickIt</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969412"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969412"><span class="hs-identifier hs-var">k</span></a></span></span><span class="hs-special">)</span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; CallCtxt
</span><a href="#local-6989586621680969419"><span class="hs-identifier hs-var">interesting</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969412"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-719"></span><span>    </span><span class="annot"><a href="#local-6989586621680969419"><span class="hs-identifier hs-var">interesting</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToTy"><span class="hs-identifier hs-type">ApplyToTy</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_cont :: SimplCont -&gt; SimplCont
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_cont"><span class="hs-identifier hs-var">sc_cont</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969411"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969411"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; CallCtxt
</span><a href="#local-6989586621680969419"><span class="hs-identifier hs-var">interesting</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969411"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-720"></span><span>    </span><span class="annot"><a href="#local-6989586621680969419"><span class="hs-identifier hs-var">interesting</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastIt"><span class="hs-identifier hs-type">CastIt</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969410"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969410"><span class="hs-identifier hs-var">k</span></a></span></span><span class="hs-special">)</span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; CallCtxt
</span><a href="#local-6989586621680969419"><span class="hs-identifier hs-var">interesting</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969410"><span class="hs-identifier hs-var">k</span></a></span><span>
</span><span id="line-721"></span><span>        </span><span class="hs-comment">-- If this call is the arg of a strict function, the context</span><span>
</span><span id="line-722"></span><span>        </span><span class="hs-comment">-- is a bit interesting.  If we inline here, we may get useful</span><span>
</span><span id="line-723"></span><span>        </span><span class="hs-comment">-- evaluation information to avoid repeated evals: e.g.</span><span>
</span><span id="line-724"></span><span>        </span><span class="hs-comment">--      x + (y * z)</span><span>
</span><span id="line-725"></span><span>        </span><span class="hs-comment">-- Here the contIsInteresting makes the '*' keener to inline,</span><span>
</span><span id="line-726"></span><span>        </span><span class="hs-comment">-- which in turn exposes a constructor which makes the '+' inline.</span><span>
</span><span id="line-727"></span><span>        </span><span class="hs-comment">-- Assuming that +,* aren't small enough to inline regardless.</span><span>
</span><span id="line-728"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-729"></span><span>        </span><span class="hs-comment">-- It's also very important to inline in a strict context for things</span><span>
</span><span id="line-730"></span><span>        </span><span class="hs-comment">-- like</span><span>
</span><span id="line-731"></span><span>        </span><span class="hs-comment">--              foldr k z (f x)</span><span>
</span><span id="line-732"></span><span>        </span><span class="hs-comment">-- Here, the context of (f x) is strict, and if f's unfolding is</span><span>
</span><span id="line-733"></span><span>        </span><span class="hs-comment">-- a build it's *great* to inline it here.  So we must ensure that</span><span>
</span><span id="line-734"></span><span>        </span><span class="hs-comment">-- the context for (f x) is not totally uninteresting.</span><span>
</span><span id="line-735"></span><span>
</span><span id="line-736"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#interestingArgContext"><span class="hs-identifier hs-type">interestingArgContext</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreRule"><span class="hs-identifier hs-type">CoreRule</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-737"></span><span class="hs-comment">-- If the argument has form (f x y), where x,y are boring,</span><span>
</span><span id="line-738"></span><span class="hs-comment">-- and f is marked INLINE, then we don't want to inline f.</span><span>
</span><span id="line-739"></span><span class="hs-comment">-- But if the context of the argument is</span><span>
</span><span id="line-740"></span><span class="hs-comment">--      g (f x y)</span><span>
</span><span id="line-741"></span><span class="hs-comment">-- where g has rules, then we *do* want to inline f, in case it</span><span>
</span><span id="line-742"></span><span class="hs-comment">-- exposes a rule that might fire.  Similarly, if the context is</span><span>
</span><span id="line-743"></span><span class="hs-comment">--      h (g (f x x))</span><span>
</span><span id="line-744"></span><span class="hs-comment">-- where h has rules, then we do want to inline f; hence the</span><span>
</span><span id="line-745"></span><span class="hs-comment">-- call_cont argument to interestingArgContext</span><span>
</span><span id="line-746"></span><span class="hs-comment">--</span><span>
</span><span id="line-747"></span><span class="hs-comment">-- The ai-rules flag makes this happen; if it's</span><span>
</span><span id="line-748"></span><span class="hs-comment">-- set, the inliner gets just enough keener to inline f</span><span>
</span><span id="line-749"></span><span class="hs-comment">-- regardless of how boring f's arguments are, if it's marked INLINE</span><span>
</span><span id="line-750"></span><span class="hs-comment">--</span><span>
</span><span id="line-751"></span><span class="hs-comment">-- The alternative would be to *always* inline an INLINE function,</span><span>
</span><span id="line-752"></span><span class="hs-comment">-- regardless of how boring its context is; but that seems overkill</span><span>
</span><span id="line-753"></span><span class="hs-comment">-- For example, it'd mean that wrapper functions were always inlined</span><span>
</span><span id="line-754"></span><span class="hs-comment">--</span><span>
</span><span id="line-755"></span><span class="hs-comment">-- The call_cont passed to interestingArgContext is the context of</span><span>
</span><span id="line-756"></span><span class="hs-comment">-- the call itself, e.g. g &lt;hole&gt; in the example above</span><span>
</span><span id="line-757"></span><span id="interestingArgContext"><span class="annot"><span class="annottext">interestingArgContext :: [CoreRule] -&gt; SimplCont -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#interestingArgContext"><span class="hs-identifier hs-var hs-var">interestingArgContext</span></a></span></span><span> </span><span id="local-6989586621680969409"><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680969409"><span class="hs-identifier hs-var">rules</span></a></span></span><span> </span><span id="local-6989586621680969408"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969408"><span class="hs-identifier hs-var">call_cont</span></a></span></span><span>
</span><span id="line-758"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[CoreRule] -&gt; Bool
forall a. [a] -&gt; Bool
</span><a href="GHC.Utils.Misc.html#notNull"><span class="hs-identifier hs-var">notNull</span></a></span><span> </span><span class="annot"><span class="annottext">[CoreRule]
</span><a href="#local-6989586621680969409"><span class="hs-identifier hs-var">rules</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969405"><span class="hs-identifier hs-var">enclosing_fn_has_rules</span></a></span><span>
</span><span id="line-759"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-760"></span><span>    </span><span id="local-6989586621680969405"><span class="annot"><span class="annottext">enclosing_fn_has_rules :: Bool
</span><a href="#local-6989586621680969405"><span class="hs-identifier hs-var hs-var">enclosing_fn_has_rules</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; Bool
</span><a href="#local-6989586621680969404"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969408"><span class="hs-identifier hs-var">call_cont</span></a></span><span>
</span><span id="line-761"></span><span>
</span><span id="line-762"></span><span>    </span><span id="local-6989586621680969404"><span class="annot"><span class="annottext">go :: SimplCont -&gt; Bool
</span><a href="#local-6989586621680969404"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Select"><span class="hs-identifier hs-type">Select</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>                  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-763"></span><span>    </span><span class="annot"><a href="#local-6989586621680969404"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToVal"><span class="hs-identifier hs-type">ApplyToVal</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>  </span><span class="hs-comment">-- Shouldn't really happen</span><span>
</span><span id="line-764"></span><span>    </span><span class="annot"><a href="#local-6989586621680969404"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#ApplyToTy"><span class="hs-identifier hs-type">ApplyToTy</span></a></span><span>  </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>  </span><span class="hs-comment">-- Ditto</span><span>
</span><span id="line-765"></span><span>    </span><span class="annot"><a href="#local-6989586621680969404"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictArg"><span class="hs-identifier hs-type">StrictArg</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sc_fun :: SimplCont -&gt; ArgInfo
</span><a href="GHC.Core.Opt.Simplify.Utils.html#sc_fun"><span class="hs-identifier hs-var">sc_fun</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969403"><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969403"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgInfo -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#ai_encl"><span class="hs-identifier hs-var hs-var">ai_encl</span></a></span><span> </span><span class="annot"><span class="annottext">ArgInfo
</span><a href="#local-6989586621680969403"><span class="hs-identifier hs-var">fun</span></a></span><span>
</span><span id="line-766"></span><span>    </span><span class="annot"><a href="#local-6989586621680969404"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StrictBind"><span class="hs-identifier hs-type">StrictBind</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>      </span><span class="hs-comment">-- ??</span><span>
</span><span id="line-767"></span><span>    </span><span class="annot"><a href="#local-6989586621680969404"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#CastIt"><span class="hs-identifier hs-type">CastIt</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969402"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969402"><span class="hs-identifier hs-var">c</span></a></span></span><span class="hs-special">)</span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; Bool
</span><a href="#local-6989586621680969404"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969402"><span class="hs-identifier hs-var">c</span></a></span><span>
</span><span id="line-768"></span><span>    </span><span class="annot"><a href="#local-6989586621680969404"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-type">Stop</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><a href="GHC.Core.Unfold.html#RuleArgCtxt"><span class="hs-identifier hs-var">RuleArgCtxt</span></a></span><span class="hs-special">)</span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-769"></span><span>    </span><span class="annot"><a href="#local-6989586621680969404"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#Stop"><span class="hs-identifier hs-type">Stop</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">CallCtxt
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>                   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-770"></span><span>    </span><span class="annot"><a href="#local-6989586621680969404"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#TickIt"><span class="hs-identifier hs-type">TickIt</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969401"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969401"><span class="hs-identifier hs-var">c</span></a></span></span><span class="hs-special">)</span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplCont -&gt; Bool
</span><a href="#local-6989586621680969404"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969401"><span class="hs-identifier hs-var">c</span></a></span><span>
</span><span id="line-771"></span><span>
</span><span id="line-772"></span><span class="hs-comment">{- Note [Interesting arguments]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An argument is interesting if it deserves a discount for unfoldings
with a discount in that argument position.  The idea is to avoid
unfolding a function that is applied only to variables that have no
unfolding (i.e. they are probably lambda bound): f x y z There is
little point in inlining f here.

Generally, *values* (like (C a b) and (\x.e)) deserve discounts.  But
we must look through lets, eg (let x = e in C a b), because the let will
float, exposing the value, if we inline.  That makes it different to
exprIsHNF.

Before 2009 we said it was interesting if the argument had *any* structure
at all; i.e. (hasSomeUnfolding v).  But does too much inlining; see #3016.

But we don't regard (f x y) as interesting, unless f is unsaturated.
If it's saturated and f hasn't inlined, then it's probably not going
to now!

Note [Conlike is interesting]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider
        f d = ...((*) d x y)...
        ... f (df d')...
where df is con-like. Then we'd really like to inline 'f' so that the
rule for (*) (df d) can fire.  To do this
  a) we give a discount for being an argument of a class-op (eg (*) d)
  b) we say that a con-like argument (eg (df d)) is interesting
-}</span><span>
</span><span id="line-802"></span><span>
</span><span id="line-803"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#interestingArg"><span class="hs-identifier hs-type">interestingArg</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#SimplEnv"><span class="hs-identifier hs-type">SimplEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unfold.html#ArgSummary"><span class="hs-identifier hs-type">ArgSummary</span></a></span><span>
</span><span id="line-804"></span><span class="hs-comment">-- See Note [Interesting arguments]</span><span>
</span><span id="line-805"></span><span id="interestingArg"><span class="annot"><span class="annottext">interestingArg :: StaticEnv -&gt; Expr Id -&gt; ArgSummary
</span><a href="GHC.Core.Opt.Simplify.Utils.html#interestingArg"><span class="hs-identifier hs-var hs-var">interestingArg</span></a></span></span><span> </span><span id="local-6989586621680969399"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969399"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680969398"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969398"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; Arity -&gt; Expr Id -&gt; ArgSummary
</span><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969399"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969398"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-806"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-807"></span><span>    </span><span class="hs-comment">-- n is # value args to which the expression is applied</span><span>
</span><span id="line-808"></span><span>    </span><span id="local-6989586621680969397"><span class="annot"><span class="annottext">go :: StaticEnv -&gt; Arity -&gt; Expr Id -&gt; ArgSummary
</span><a href="#local-6989586621680969397"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621680969392"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969392"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680969391"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969391"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680969390"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969390"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-809"></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; Id -&gt; SimplSR
</span><a href="GHC.Core.Opt.Simplify.Env.html#substId"><span class="hs-identifier hs-var">substId</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969392"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969390"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-810"></span><span>           </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#DoneId"><span class="hs-identifier hs-type">DoneId</span></a></span><span> </span><span id="local-6989586621680969387"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969387"><span class="hs-identifier hs-var">v'</span></a></span></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Id -&gt; ArgSummary
</span><a href="#local-6989586621680969386"><span class="hs-identifier hs-var">go_var</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969391"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969387"><span class="hs-identifier hs-var">v'</span></a></span><span>
</span><span id="line-811"></span><span>           </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#DoneEx"><span class="hs-identifier hs-type">DoneEx</span></a></span><span> </span><span id="local-6989586621680969384"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969384"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="annot"><span class="annottext">Maybe Arity
</span><span class="hs-identifier">_</span></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; Arity -&gt; Expr Id -&gt; ArgSummary
</span><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StaticEnv -&gt; StaticEnv
</span><a href="GHC.Core.Opt.Simplify.Env.html#zapSubstEnv"><span class="hs-identifier hs-var">zapSubstEnv</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969392"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span>             </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969391"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969384"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-812"></span><span>           </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#ContEx"><span class="hs-identifier hs-type">ContEx</span></a></span><span> </span><span id="local-6989586621680969381"><span class="annot"><span class="annottext">TvSubstEnv
</span><a href="#local-6989586621680969381"><span class="hs-identifier hs-var">tvs</span></a></span></span><span> </span><span id="local-6989586621680969380"><span class="annot"><span class="annottext">CvSubstEnv
</span><a href="#local-6989586621680969380"><span class="hs-identifier hs-var">cvs</span></a></span></span><span> </span><span id="local-6989586621680969379"><span class="annot"><span class="annottext">SimplIdSubst
</span><a href="#local-6989586621680969379"><span class="hs-identifier hs-var">ids</span></a></span></span><span> </span><span id="local-6989586621680969378"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969378"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; Arity -&gt; Expr Id -&gt; ArgSummary
</span><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StaticEnv -&gt; TvSubstEnv -&gt; CvSubstEnv -&gt; SimplIdSubst -&gt; StaticEnv
</span><a href="GHC.Core.Opt.Simplify.Env.html#setSubstEnv"><span class="hs-identifier hs-var">setSubstEnv</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969392"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">TvSubstEnv
</span><a href="#local-6989586621680969381"><span class="hs-identifier hs-var">tvs</span></a></span><span> </span><span class="annot"><span class="annottext">CvSubstEnv
</span><a href="#local-6989586621680969380"><span class="hs-identifier hs-var">cvs</span></a></span><span> </span><span class="annot"><span class="annottext">SimplIdSubst
</span><a href="#local-6989586621680969379"><span class="hs-identifier hs-var">ids</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969391"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969378"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-813"></span><span>
</span><span id="line-814"></span><span>    </span><span class="annot"><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><span class="hs-identifier">_</span></span><span>   </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lit"><span class="hs-identifier hs-type">Lit</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#ValueArg"><span class="hs-identifier hs-var">ValueArg</span></a></span><span>
</span><span id="line-815"></span><span>    </span><span class="annot"><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><span class="hs-identifier">_</span></span><span>   </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#TrivArg"><span class="hs-identifier hs-var">TrivArg</span></a></span><span>
</span><span id="line-816"></span><span>    </span><span class="annot"><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><span class="hs-identifier">_</span></span><span>   </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#TrivArg"><span class="hs-identifier hs-var">TrivArg</span></a></span><span>
</span><span id="line-817"></span><span>    </span><span class="annot"><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680969373"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969373"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680969372"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969372"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680969371"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969371"><span class="hs-identifier hs-var">fn</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; Arity -&gt; Expr Id -&gt; ArgSummary
</span><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969373"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969372"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969371"><span class="hs-identifier hs-var">fn</span></a></span><span>
</span><span id="line-818"></span><span>    </span><span class="annot"><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680969370"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969370"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680969369"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969369"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680969368"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969368"><span class="hs-identifier hs-var">fn</span></a></span></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; Arity -&gt; Expr Id -&gt; ArgSummary
</span><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969370"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969369"><span class="hs-identifier hs-var">n</span></a></span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Arity
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969368"><span class="hs-identifier hs-var">fn</span></a></span><span>
</span><span id="line-819"></span><span>    </span><span class="annot"><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680969367"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969367"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680969366"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969366"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969364"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969364"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">)</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; Arity -&gt; Expr Id -&gt; ArgSummary
</span><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969367"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969366"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969364"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-820"></span><span>    </span><span class="annot"><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680969363"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969363"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680969362"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969362"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-type">Cast</span></a></span><span> </span><span id="local-6989586621680969360"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969360"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; Arity -&gt; Expr Id -&gt; ArgSummary
</span><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969363"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969362"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969360"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-821"></span><span>    </span><span class="annot"><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680969359"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969359"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680969358"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969358"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lam"><span class="hs-identifier hs-type">Lam</span></a></span><span> </span><span id="local-6989586621680969356"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969356"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span id="local-6989586621680969355"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969355"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-822"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Var.html#isTyVar"><span class="hs-identifier hs-var">isTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969356"><span class="hs-identifier hs-var">v</span></a></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; Arity -&gt; Expr Id -&gt; ArgSummary
</span><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969359"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969358"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969355"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-823"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969358"><span class="hs-identifier hs-var">n</span></a></span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">0</span></span><span>                   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#NonTrivArg"><span class="hs-identifier hs-var">NonTrivArg</span></a></span><span>     </span><span class="hs-comment">-- (\x.b) e   is NonTriv</span><span>
</span><span id="line-824"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#ValueArg"><span class="hs-identifier hs-var">ValueArg</span></a></span><span>
</span><span id="line-825"></span><span>    </span><span class="annot"><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Case"><span class="hs-identifier hs-type">Case</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#NonTrivArg"><span class="hs-identifier hs-var">NonTrivArg</span></a></span><span>
</span><span id="line-826"></span><span>    </span><span class="annot"><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680969351"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969351"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680969350"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969350"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Let"><span class="hs-identifier hs-type">Let</span></a></span><span> </span><span id="local-6989586621680969348"><span class="annot"><span class="annottext">Bind Id
</span><a href="#local-6989586621680969348"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span id="local-6989586621680969347"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969347"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; Arity -&gt; Expr Id -&gt; ArgSummary
</span><a href="#local-6989586621680969397"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969346"><span class="hs-identifier hs-var">env'</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969350"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969347"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-827"></span><span>                                   </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#ValueArg"><span class="hs-identifier hs-var">ValueArg</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#ValueArg"><span class="hs-identifier hs-var">ValueArg</span></a></span><span>
</span><span id="line-828"></span><span>                                   </span><span class="annot"><span class="annottext">ArgSummary
</span><span class="hs-identifier">_</span></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#NonTrivArg"><span class="hs-identifier hs-var">NonTrivArg</span></a></span><span>
</span><span id="line-829"></span><span>                               </span><span class="hs-keyword">where</span><span>
</span><span id="line-830"></span><span>                                 </span><span id="local-6989586621680969346"><span class="annot"><span class="annottext">env' :: StaticEnv
</span><a href="#local-6989586621680969346"><span class="hs-identifier hs-var hs-var">env'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969351"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; [Id] -&gt; StaticEnv
</span><a href="GHC.Core.Opt.Simplify.Env.html#addNewInScopeIds"><span class="hs-operator hs-var">`addNewInScopeIds`</span></a></span><span> </span><span class="annot"><span class="annottext">Bind Id -&gt; [Id]
forall b. Bind b -&gt; [b]
</span><a href="GHC.Core.html#bindersOf"><span class="hs-identifier hs-var">bindersOf</span></a></span><span> </span><span class="annot"><span class="annottext">Bind Id
</span><a href="#local-6989586621680969348"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-831"></span><span>
</span><span id="line-832"></span><span>    </span><span id="local-6989586621680969386"><span class="annot"><span class="annottext">go_var :: Arity -&gt; Id -&gt; ArgSummary
</span><a href="#local-6989586621680969386"><span class="hs-identifier hs-var hs-var">go_var</span></a></span></span><span> </span><span id="local-6989586621680969340"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969340"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span id="local-6989586621680969339"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969339"><span class="hs-identifier hs-var">v</span></a></span></span><span>
</span><span id="line-833"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Id.html#isConLikeId"><span class="hs-identifier hs-var">isConLikeId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969339"><span class="hs-identifier hs-var">v</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#ValueArg"><span class="hs-identifier hs-var">ValueArg</span></a></span><span>   </span><span class="hs-comment">-- Experimenting with 'conlike' rather that</span><span>
</span><span id="line-834"></span><span>                                        </span><span class="hs-comment">--    data constructors here</span><span>
</span><span id="line-835"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Arity
</span><a href="GHC.Types.Id.html#idArity"><span class="hs-identifier hs-var">idArity</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969339"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969340"><span class="hs-identifier hs-var">n</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#ValueArg"><span class="hs-identifier hs-var">ValueArg</span></a></span><span>   </span><span class="hs-comment">-- Catches (eg) primops with arity but no unfolding</span><span>
</span><span id="line-836"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969340"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">0</span></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#NonTrivArg"><span class="hs-identifier hs-var">NonTrivArg</span></a></span><span> </span><span class="hs-comment">-- Saturated or unknown call</span><span>
</span><span id="line-837"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969337"><span class="hs-identifier hs-var">conlike_unfolding</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#ValueArg"><span class="hs-identifier hs-var">ValueArg</span></a></span><span>   </span><span class="hs-comment">-- n==0; look for an interesting unfolding</span><span>
</span><span id="line-838"></span><span>                                        </span><span class="hs-comment">-- See Note [Conlike is interesting]</span><span>
</span><span id="line-839"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArgSummary
</span><a href="GHC.Core.Unfold.html#TrivArg"><span class="hs-identifier hs-var">TrivArg</span></a></span><span>    </span><span class="hs-comment">-- n==0, no useful unfolding</span><span>
</span><span id="line-840"></span><span>       </span><span class="hs-keyword">where</span><span>
</span><span id="line-841"></span><span>         </span><span id="local-6989586621680969337"><span class="annot"><span class="annottext">conlike_unfolding :: Bool
</span><a href="#local-6989586621680969337"><span class="hs-identifier hs-var hs-var">conlike_unfolding</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Unfolding -&gt; Bool
</span><a href="GHC.Core.html#isConLikeUnfolding"><span class="hs-identifier hs-var">isConLikeUnfolding</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Unfolding
</span><a href="GHC.Types.Id.html#idUnfolding"><span class="hs-identifier hs-var">idUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969339"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-842"></span><span>
</span><span id="line-843"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
                  SimplMode
*                                                                      *
************************************************************************

The SimplMode controls several switches; see its definition in
GHC.Core.Opt.Monad
        sm_rules      :: Bool     -- Whether RULES are enabled
        sm_inline     :: Bool     -- Whether inlining is enabled
        sm_case_case  :: Bool     -- Whether case-of-case is enabled
        sm_eta_expand :: Bool     -- Whether eta-expansion is enabled
-}</span><span>
</span><span id="line-857"></span><span>
</span><span id="line-858"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#simplEnvForGHCi"><span class="hs-identifier hs-type">simplEnvForGHCi</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#SimplEnv"><span class="hs-identifier hs-type">SimplEnv</span></a></span><span>
</span><span id="line-859"></span><span id="simplEnvForGHCi"><span class="annot"><span class="annottext">simplEnvForGHCi :: DynFlags -&gt; StaticEnv
</span><a href="GHC.Core.Opt.Simplify.Utils.html#simplEnvForGHCi"><span class="hs-identifier hs-var hs-var">simplEnvForGHCi</span></a></span></span><span> </span><span id="local-6989586621680969335"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969335"><span class="hs-identifier hs-var">dflags</span></a></span></span><span>
</span><span id="line-860"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplMode -&gt; StaticEnv
</span><a href="GHC.Core.Opt.Simplify.Env.html#mkSimplEnv"><span class="hs-identifier hs-var">mkSimplEnv</span></a></span><span> </span><span class="annot"><span class="annottext">(SimplMode -&gt; StaticEnv) -&gt; SimplMode -&gt; StaticEnv
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">SimplMode :: [String]
-&gt; CompilerPhase
-&gt; DynFlags
-&gt; Bool
-&gt; Bool
-&gt; Bool
-&gt; Bool
-&gt; SimplMode
</span><a href="GHC.Core.Opt.Monad.html#SimplMode"><span class="hs-identifier hs-type">SimplMode</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sm_names :: [String]
</span><a href="GHC.Core.Opt.Monad.html#sm_names"><span class="hs-identifier hs-var">sm_names</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;GHCi&quot;</span></span><span class="hs-special">]</span><span>
</span><span id="line-861"></span><span>                           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sm_phase :: CompilerPhase
</span><a href="GHC.Core.Opt.Monad.html#sm_phase"><span class="hs-identifier hs-var">sm_phase</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CompilerPhase
</span><a href="GHC.Types.Basic.html#InitialPhase"><span class="hs-identifier hs-var">InitialPhase</span></a></span><span>
</span><span id="line-862"></span><span>                           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sm_dflags :: DynFlags
</span><a href="GHC.Core.Opt.Monad.html#sm_dflags"><span class="hs-identifier hs-var">sm_dflags</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969335"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-863"></span><span>                           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sm_rules :: Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_rules"><span class="hs-identifier hs-var">sm_rules</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969327"><span class="hs-identifier hs-var">rules_on</span></a></span><span>
</span><span id="line-864"></span><span>                           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sm_inline :: Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_inline"><span class="hs-identifier hs-var">sm_inline</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-865"></span><span>                           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sm_eta_expand :: Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_eta_expand"><span class="hs-identifier hs-var">sm_eta_expand</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969325"><span class="hs-identifier hs-var">eta_expand_on</span></a></span><span>
</span><span id="line-866"></span><span>                           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sm_case_case :: Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_case_case"><span class="hs-identifier hs-var">sm_case_case</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-867"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-868"></span><span>    </span><span id="local-6989586621680969327"><span class="annot"><span class="annottext">rules_on :: Bool
</span><a href="#local-6989586621680969327"><span class="hs-identifier hs-var hs-var">rules_on</span></a></span></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">GeneralFlag -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#gopt"><span class="hs-identifier hs-var">gopt</span></a></span><span> </span><span class="annot"><span class="annottext">GeneralFlag
</span><a href="GHC.Driver.Flags.html#Opt_EnableRewriteRules"><span class="hs-identifier hs-var">Opt_EnableRewriteRules</span></a></span><span>   </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969335"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-869"></span><span>    </span><span id="local-6989586621680969325"><span class="annot"><span class="annottext">eta_expand_on :: Bool
</span><a href="#local-6989586621680969325"><span class="hs-identifier hs-var hs-var">eta_expand_on</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">GeneralFlag -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#gopt"><span class="hs-identifier hs-var">gopt</span></a></span><span> </span><span class="annot"><span class="annottext">GeneralFlag
</span><a href="GHC.Driver.Flags.html#Opt_DoLambdaEtaExpansion"><span class="hs-identifier hs-var">Opt_DoLambdaEtaExpansion</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969335"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-870"></span><span>   </span><span class="hs-comment">-- Do not do any inlining, in case we expose some unboxed</span><span>
</span><span id="line-871"></span><span>   </span><span class="hs-comment">-- tuple stuff that confuses the bytecode interpreter</span><span>
</span><span id="line-872"></span><span>
</span><span id="line-873"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#updModeForStableUnfoldings"><span class="hs-identifier hs-type">updModeForStableUnfoldings</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#Activation"><span class="hs-identifier hs-type">Activation</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Monad.html#SimplMode"><span class="hs-identifier hs-type">SimplMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Monad.html#SimplMode"><span class="hs-identifier hs-type">SimplMode</span></a></span><span>
</span><span id="line-874"></span><span class="hs-comment">-- See Note [Simplifying inside stable unfoldings]</span><span>
</span><span id="line-875"></span><span id="updModeForStableUnfoldings"><span class="annot"><span class="annottext">updModeForStableUnfoldings :: Activation -&gt; SimplMode -&gt; SimplMode
</span><a href="GHC.Core.Opt.Simplify.Utils.html#updModeForStableUnfoldings"><span class="hs-identifier hs-var hs-var">updModeForStableUnfoldings</span></a></span></span><span> </span><span id="local-6989586621680969321"><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621680969321"><span class="hs-identifier hs-var">inline_rule_act</span></a></span></span><span> </span><span id="local-6989586621680969320"><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969320"><span class="hs-identifier hs-var">current_mode</span></a></span></span><span>
</span><span id="line-876"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969320"><span class="hs-identifier hs-var">current_mode</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sm_phase :: CompilerPhase
</span><a href="GHC.Core.Opt.Monad.html#sm_phase"><span class="hs-identifier hs-var">sm_phase</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Activation -&gt; CompilerPhase
</span><a href="#local-6989586621680969319"><span class="hs-identifier hs-var">phaseFromActivation</span></a></span><span> </span><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621680969321"><span class="hs-identifier hs-var">inline_rule_act</span></a></span><span>
</span><span id="line-877"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sm_inline :: Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_inline"><span class="hs-identifier hs-var">sm_inline</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-878"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sm_eta_expand :: Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_eta_expand"><span class="hs-identifier hs-var">sm_eta_expand</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-879"></span><span>                     </span><span class="hs-comment">-- sm_eta_expand: see Note [No eta expansion in stable unfoldings]</span><span>
</span><span id="line-880"></span><span>       </span><span class="hs-comment">-- For sm_rules, just inherit; sm_rules might be &quot;off&quot;</span><span>
</span><span id="line-881"></span><span>       </span><span class="hs-comment">-- because of -fno-enable-rewrite-rules</span><span>
</span><span id="line-882"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-883"></span><span>    </span><span id="local-6989586621680969319"><span class="annot"><span class="annottext">phaseFromActivation :: Activation -&gt; CompilerPhase
</span><a href="#local-6989586621680969319"><span class="hs-identifier hs-var hs-var">phaseFromActivation</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Basic.html#ActiveAfter"><span class="hs-identifier hs-type">ActiveAfter</span></a></span><span> </span><span class="annot"><span class="annottext">SourceText
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969317"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969317"><span class="hs-identifier hs-var">n</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; CompilerPhase
</span><a href="GHC.Types.Basic.html#Phase"><span class="hs-identifier hs-var">Phase</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969317"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-884"></span><span>    </span><span class="annot"><a href="#local-6989586621680969319"><span class="hs-identifier hs-var">phaseFromActivation</span></a></span><span> </span><span class="annot"><span class="annottext">Activation
</span><span class="hs-identifier">_</span></span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CompilerPhase
</span><a href="GHC.Types.Basic.html#InitialPhase"><span class="hs-identifier hs-var">InitialPhase</span></a></span><span>
</span><span id="line-885"></span><span>
</span><span id="line-886"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#updModeForRules"><span class="hs-identifier hs-type">updModeForRules</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Monad.html#SimplMode"><span class="hs-identifier hs-type">SimplMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Monad.html#SimplMode"><span class="hs-identifier hs-type">SimplMode</span></a></span><span>
</span><span id="line-887"></span><span class="hs-comment">-- See Note [Simplifying rules]</span><span>
</span><span id="line-888"></span><span id="updModeForRules"><span class="annot"><span class="annottext">updModeForRules :: SimplMode -&gt; SimplMode
</span><a href="GHC.Core.Opt.Simplify.Utils.html#updModeForRules"><span class="hs-identifier hs-var hs-var">updModeForRules</span></a></span></span><span> </span><span id="local-6989586621680969315"><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969315"><span class="hs-identifier hs-var">current_mode</span></a></span></span><span>
</span><span id="line-889"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969315"><span class="hs-identifier hs-var">current_mode</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">sm_phase :: CompilerPhase
</span><a href="GHC.Core.Opt.Monad.html#sm_phase"><span class="hs-identifier hs-var">sm_phase</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CompilerPhase
</span><a href="GHC.Types.Basic.html#InitialPhase"><span class="hs-identifier hs-var">InitialPhase</span></a></span><span>
</span><span id="line-890"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sm_inline :: Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_inline"><span class="hs-identifier hs-var">sm_inline</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>  </span><span class="hs-comment">-- See Note [Do not expose strictness if sm_inline=False]</span><span>
</span><span id="line-891"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sm_rules :: Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_rules"><span class="hs-identifier hs-var">sm_rules</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-892"></span><span>                 </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">sm_eta_expand :: Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_eta_expand"><span class="hs-identifier hs-var">sm_eta_expand</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-893"></span><span>
</span><span id="line-894"></span><span class="hs-comment">{- Note [Simplifying rules]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When simplifying a rule LHS, refrain from /any/ inlining or applying
of other RULES.

Doing anything to the LHS is plain confusing, because it means that what the
rule matches is not what the user wrote. c.f. #10595, and #10528.
Moreover, inlining (or applying rules) on rule LHSs risks introducing
Ticks into the LHS, which makes matching trickier. #10665, #10745.

Doing this to either side confounds tools like HERMIT, which seek to reason
about and apply the RULES as originally written. See #10829.

There is, however, one case where we are pretty much /forced/ to transform the
LHS of a rule: postInlineUnconditionally. For instance, in the case of

    let f = g @Int in f

We very much want to inline f into the body of the let. However, to do so (and
be able to safely drop f's binding) we must inline into all occurrences of f,
including those in the LHS of rules.

This can cause somewhat surprising results; for instance, in #18162 we found
that a rule template contained ticks in its arguments, because
postInlineUnconditionally substituted in a trivial expression that contains
ticks. See Note [Tick annotations in RULE matching] in GHC.Core.Rules for
details.

Note [No eta expansion in stable unfoldings]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If we have a stable unfolding

  f :: Ord a =&gt; a -&gt; IO ()
  -- Unfolding template
  --    = /\a \(d:Ord a) (x:a). bla

we do not want to eta-expand to

  f :: Ord a =&gt; a -&gt; IO ()
  -- Unfolding template
  --    = (/\a \(d:Ord a) (x:a) (eta:State#). bla eta) |&gt; co

because not specialisation of the overloading doesn't work properly
(see Note [Specialisation shape] in GHC.Core.Opt.Specialise), #9509.

So we disable eta-expansion in stable unfoldings.

Note [Inlining in gentle mode]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Something is inlined if
   (i)   the sm_inline flag is on, AND
   (ii)  the thing has an INLINE pragma, AND
   (iii) the thing is inlinable in the earliest phase.

Example of why (iii) is important:
  {-# INLINE [~1] g #-}
  g = ...

  {-# INLINE f #-}
  f x = g (g x)

If we were to inline g into f's inlining, then an importing module would
never be able to do
        f e --&gt; g (g e) ---&gt; RULE fires
because the stable unfolding for f has had g inlined into it.

On the other hand, it is bad not to do ANY inlining into an
stable unfolding, because then recursive knots in instance declarations
don't get unravelled.

However, *sometimes* SimplGently must do no call-site inlining at all
(hence sm_inline = False).  Before full laziness we must be careful
not to inline wrappers, because doing so inhibits floating
    e.g. ...(case f x of ...)...
    ==&gt; ...(case (case x of I# x# -&gt; fw x#) of ...)...
    ==&gt; ...(case x of I# x# -&gt; case fw x# of ...)...
and now the redex (f x) isn't floatable any more.

The no-inlining thing is also important for Template Haskell.  You might be
compiling in one-shot mode with -O2; but when TH compiles a splice before
running it, we don't want to use -O2.  Indeed, we don't want to inline
anything, because the byte-code interpreter might get confused about
unboxed tuples and suchlike.

Note [Simplifying inside stable unfoldings]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We must take care with simplification inside stable unfoldings (which come from
INLINE pragmas).

First, consider the following example
        let f = \pq -&gt; BIG
        in
        let g = \y -&gt; f y y
            {-# INLINE g #-}
        in ...g...g...g...g...g...
Now, if that's the ONLY occurrence of f, it might be inlined inside g,
and thence copied multiple times when g is inlined. HENCE we treat
any occurrence in a stable unfolding as a multiple occurrence, not a single
one; see OccurAnal.addRuleUsage.

Second, we do want *do* to some modest rules/inlining stuff in stable
unfoldings, partly to eliminate senseless crap, and partly to break
the recursive knots generated by instance declarations.

However, suppose we have
        {-# INLINE &lt;act&gt; f #-}
        f = &lt;rhs&gt;
meaning &quot;inline f in phases p where activation &lt;act&gt;(p) holds&quot;.
Then what inlinings/rules can we apply to the copy of &lt;rhs&gt; captured in
f's stable unfolding?  Our model is that literally &lt;rhs&gt; is substituted for
f when it is inlined.  So our conservative plan (implemented by
updModeForStableUnfoldings) is this:

  -------------------------------------------------------------
  When simplifying the RHS of a stable unfolding, set the phase
  to the phase in which the stable unfolding first becomes active
  -------------------------------------------------------------

That ensures that

  a) Rules/inlinings that *cease* being active before p will
     not apply to the stable unfolding, consistent with it being
     inlined in its *original* form in phase p.

  b) Rules/inlinings that only become active *after* p will
     not apply to the stable unfolding, again to be consistent with
     inlining the *original* rhs in phase p.

For example,
        {-# INLINE f #-}
        f x = ...g...

        {-# NOINLINE [1] g #-}
        g y = ...

        {-# RULE h g = ... #-}
Here we must not inline g into f's RHS, even when we get to phase 0,
because when f is later inlined into some other module we want the
rule for h to fire.

Similarly, consider
        {-# INLINE f #-}
        f x = ...g...

        g y = ...
and suppose that there are auto-generated specialisations and a strictness
wrapper for g.  The specialisations get activation AlwaysActive, and the
strictness wrapper get activation (ActiveAfter 0).  So the strictness
wrepper fails the test and won't be inlined into f's stable unfolding. That
means f can inline, expose the specialised call to g, so the specialisation
rules can fire.

A note about wrappers
~~~~~~~~~~~~~~~~~~~~~
It's also important not to inline a worker back into a wrapper.
A wrapper looks like
        wraper = inline_me (\x -&gt; ...worker... )
Normally, the inline_me prevents the worker getting inlined into
the wrapper (initially, the worker's only call site!).  But,
if the wrapper is sure to be called, the strictness analyser will
mark it 'demanded', so when the RHS is simplified, it'll get an ArgOf
continuation.
-}</span><span>
</span><span id="line-1057"></span><span>
</span><span id="line-1058"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#activeUnfolding"><span class="hs-identifier hs-type">activeUnfolding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Monad.html#SimplMode"><span class="hs-identifier hs-type">SimplMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-1059"></span><span id="activeUnfolding"><span class="annot"><span class="annottext">activeUnfolding :: SimplMode -&gt; Id -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#activeUnfolding"><span class="hs-identifier hs-var hs-var">activeUnfolding</span></a></span></span><span> </span><span id="local-6989586621680969314"><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969314"><span class="hs-identifier hs-var">mode</span></a></span></span><span> </span><span id="local-6989586621680969313"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969313"><span class="hs-identifier hs-var">id</span></a></span></span><span>
</span><span id="line-1060"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Unfolding -&gt; Bool
</span><a href="GHC.Core.html#isCompulsoryUnfolding"><span class="hs-identifier hs-var">isCompulsoryUnfolding</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Unfolding
</span><a href="GHC.Types.Id.html#realIdUnfolding"><span class="hs-identifier hs-var">realIdUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969313"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1061"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>   </span><span class="hs-comment">-- Even sm_inline can't override compulsory unfoldings</span><span>
</span><span id="line-1062"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1063"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CompilerPhase -&gt; Activation -&gt; Bool
</span><a href="GHC.Types.Basic.html#isActive"><span class="hs-identifier hs-var">isActive</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SimplMode -&gt; CompilerPhase
</span><a href="GHC.Core.Opt.Monad.html#sm_phase"><span class="hs-identifier hs-var hs-var">sm_phase</span></a></span><span> </span><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969314"><span class="hs-identifier hs-var">mode</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Activation
</span><a href="GHC.Types.Id.html#idInlineActivation"><span class="hs-identifier hs-var">idInlineActivation</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969313"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1064"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">SimplMode -&gt; Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_inline"><span class="hs-identifier hs-var hs-var">sm_inline</span></a></span><span> </span><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969314"><span class="hs-identifier hs-var">mode</span></a></span><span>
</span><span id="line-1065"></span><span>      </span><span class="hs-comment">-- `or` isStableUnfolding (realIdUnfolding id)</span><span>
</span><span id="line-1066"></span><span>      </span><span class="hs-comment">-- Inline things when</span><span>
</span><span id="line-1067"></span><span>      </span><span class="hs-comment">--  (a) they are active</span><span>
</span><span id="line-1068"></span><span>      </span><span class="hs-comment">--  (b) sm_inline says so, except that for stable unfoldings</span><span>
</span><span id="line-1069"></span><span>      </span><span class="hs-comment">--                         (ie pragmas) we inline anyway</span><span>
</span><span id="line-1070"></span><span>
</span><span id="line-1071"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#getUnfoldingInRuleMatch"><span class="hs-identifier hs-type">getUnfoldingInRuleMatch</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#SimplEnv"><span class="hs-identifier hs-type">SimplEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#InScopeEnv"><span class="hs-identifier hs-type">InScopeEnv</span></a></span><span>
</span><span id="line-1072"></span><span class="hs-comment">-- When matching in RULE, we want to &quot;look through&quot; an unfolding</span><span>
</span><span id="line-1073"></span><span class="hs-comment">-- (to see a constructor) if *rules* are on, even if *inlinings*</span><span>
</span><span id="line-1074"></span><span class="hs-comment">-- are not.  A notable example is DFuns, which really we want to</span><span>
</span><span id="line-1075"></span><span class="hs-comment">-- match in rules like (op dfun) in gentle mode. Another example</span><span>
</span><span id="line-1076"></span><span class="hs-comment">-- is 'otherwise' which we want exprIsConApp_maybe to be able to</span><span>
</span><span id="line-1077"></span><span class="hs-comment">-- see very early on</span><span>
</span><span id="line-1078"></span><span id="getUnfoldingInRuleMatch"><span class="annot"><span class="annottext">getUnfoldingInRuleMatch :: StaticEnv -&gt; InScopeEnv
</span><a href="GHC.Core.Opt.Simplify.Utils.html#getUnfoldingInRuleMatch"><span class="hs-identifier hs-var hs-var">getUnfoldingInRuleMatch</span></a></span></span><span> </span><span id="local-6989586621680969307"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969307"><span class="hs-identifier hs-var">env</span></a></span></span><span>
</span><span id="line-1079"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680969306"><span class="hs-identifier hs-var">in_scope</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Unfolding
</span><a href="#local-6989586621680969305"><span class="hs-identifier hs-var">id_unf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1080"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1081"></span><span>    </span><span id="local-6989586621680969306"><span class="annot"><span class="annottext">in_scope :: InScopeSet
</span><a href="#local-6989586621680969306"><span class="hs-identifier hs-var hs-var">in_scope</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; InScopeSet
</span><a href="GHC.Core.Opt.Simplify.Env.html#seInScope"><span class="hs-identifier hs-var hs-var">seInScope</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969307"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-1082"></span><span>    </span><span id="local-6989586621680969303"><span class="annot"><span class="annottext">mode :: SimplMode
</span><a href="#local-6989586621680969303"><span class="hs-identifier hs-var hs-var">mode</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; SimplMode
</span><a href="GHC.Core.Opt.Simplify.Env.html#getMode"><span class="hs-identifier hs-var">getMode</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969307"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-1083"></span><span>    </span><span id="local-6989586621680969305"><span class="annot"><span class="annottext">id_unf :: Id -&gt; Unfolding
</span><a href="#local-6989586621680969305"><span class="hs-identifier hs-var hs-var">id_unf</span></a></span></span><span> </span><span id="local-6989586621680969302"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969302"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="#local-6989586621680969301"><span class="hs-identifier hs-var">unf_is_active</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969302"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Unfolding
</span><a href="GHC.Types.Id.html#idUnfolding"><span class="hs-identifier hs-var">idUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969302"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-1084"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><a href="GHC.Core.html#NoUnfolding"><span class="hs-identifier hs-var">NoUnfolding</span></a></span><span>
</span><span id="line-1085"></span><span>    </span><span id="local-6989586621680969301"><span class="annot"><span class="annottext">unf_is_active :: Id -&gt; Bool
</span><a href="#local-6989586621680969301"><span class="hs-identifier hs-var hs-var">unf_is_active</span></a></span></span><span> </span><span id="local-6989586621680969299"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969299"><span class="hs-identifier hs-var">id</span></a></span></span><span>
</span><span id="line-1086"></span><span>     </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SimplMode -&gt; Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_rules"><span class="hs-identifier hs-var hs-var">sm_rules</span></a></span><span> </span><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969303"><span class="hs-identifier hs-var">mode</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-comment">-- active_unfolding_minimal id</span><span>
</span><span id="line-1087"></span><span>                             </span><span class="annot"><span class="annottext">Unfolding -&gt; Bool
</span><a href="GHC.Core.html#isStableUnfolding"><span class="hs-identifier hs-var">isStableUnfolding</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Unfolding
</span><a href="GHC.Types.Id.html#realIdUnfolding"><span class="hs-identifier hs-var">realIdUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969299"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1088"></span><span>        </span><span class="hs-comment">-- Do we even need to test this?  I think this InScopeEnv</span><span>
</span><span id="line-1089"></span><span>        </span><span class="hs-comment">-- is only consulted if activeRule returns True, which</span><span>
</span><span id="line-1090"></span><span>        </span><span class="hs-comment">-- never happens if sm_rules is False</span><span>
</span><span id="line-1091"></span><span>     </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CompilerPhase -&gt; Activation -&gt; Bool
</span><a href="GHC.Types.Basic.html#isActive"><span class="hs-identifier hs-var">isActive</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SimplMode -&gt; CompilerPhase
</span><a href="GHC.Core.Opt.Monad.html#sm_phase"><span class="hs-identifier hs-var hs-var">sm_phase</span></a></span><span> </span><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969303"><span class="hs-identifier hs-var">mode</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Activation
</span><a href="GHC.Types.Id.html#idInlineActivation"><span class="hs-identifier hs-var">idInlineActivation</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969299"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1092"></span><span>
</span><span id="line-1093"></span><span class="hs-comment">----------------------</span><span>
</span><span id="line-1094"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#activeRule"><span class="hs-identifier hs-type">activeRule</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Monad.html#SimplMode"><span class="hs-identifier hs-type">SimplMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#Activation"><span class="hs-identifier hs-type">Activation</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-1095"></span><span class="hs-comment">-- Nothing =&gt; No rules at all</span><span>
</span><span id="line-1096"></span><span id="activeRule"><span class="annot"><span class="annottext">activeRule :: SimplMode -&gt; Activation -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#activeRule"><span class="hs-identifier hs-var hs-var">activeRule</span></a></span></span><span> </span><span id="local-6989586621680969297"><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969297"><span class="hs-identifier hs-var">mode</span></a></span></span><span>
</span><span id="line-1097"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SimplMode -&gt; Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_rules"><span class="hs-identifier hs-var hs-var">sm_rules</span></a></span><span> </span><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969297"><span class="hs-identifier hs-var">mode</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-glyph">\</span><span class="annot"><span class="annottext">Activation
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>     </span><span class="hs-comment">-- Rewriting is off</span><span>
</span><span id="line-1098"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CompilerPhase -&gt; Activation -&gt; Bool
</span><a href="GHC.Types.Basic.html#isActive"><span class="hs-identifier hs-var">isActive</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SimplMode -&gt; CompilerPhase
</span><a href="GHC.Core.Opt.Monad.html#sm_phase"><span class="hs-identifier hs-var hs-var">sm_phase</span></a></span><span> </span><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969297"><span class="hs-identifier hs-var">mode</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1099"></span><span>
</span><span id="line-1100"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
                  preInlineUnconditionally
*                                                                      *
************************************************************************

preInlineUnconditionally
~~~~~~~~~~~~~~~~~~~~~~~~
@preInlineUnconditionally@ examines a bndr to see if it is used just
once in a completely safe way, so that it is safe to discard the
binding inline its RHS at the (unique) usage site, REGARDLESS of how
big the RHS might be.  If this is the case we don't simplify the RHS
first, but just inline it un-simplified.

This is much better than first simplifying a perhaps-huge RHS and then
inlining and re-simplifying it.  Indeed, it can be at least quadratically
better.  Consider

        x1 = e1
        x2 = e2[x1]
        x3 = e3[x2]
        ...etc...
        xN = eN[xN-1]

We may end up simplifying e1 N times, e2 N-1 times, e3 N-3 times etc.
This can happen with cascades of functions too:

        f1 = \x1.e1
        f2 = \xs.e2[f1]
        f3 = \xs.e3[f3]
        ...etc...

THE MAIN INVARIANT is this:

        ----  preInlineUnconditionally invariant -----
   IF preInlineUnconditionally chooses to inline x = &lt;rhs&gt;
   THEN doing the inlining should not change the occurrence
        info for the free vars of &lt;rhs&gt;
        ----------------------------------------------

For example, it's tempting to look at trivial binding like
        x = y
and inline it unconditionally.  But suppose x is used many times,
but this is the unique occurrence of y.  Then inlining x would change
y's occurrence info, which breaks the invariant.  It matters: y
might have a BIG rhs, which will now be dup'd at every occurrence of x.


Even RHSs labelled InlineMe aren't caught here, because there might be
no benefit from inlining at the call site.

[Sept 01] Don't unconditionally inline a top-level thing, because that
can simply make a static thing into something built dynamically.  E.g.
        x = (a,b)
        main = \s -&gt; h x

[Remember that we treat \s as a one-shot lambda.]  No point in
inlining x unless there is something interesting about the call site.

But watch out: if you aren't careful, some useful foldr/build fusion
can be lost (most notably in spectral/hartel/parstof) because the
foldr didn't see the build.  Doing the dynamic allocation isn't a big
deal, in fact, but losing the fusion can be.  But the right thing here
seems to be to do a callSiteInline based on the fact that there is
something interesting about the call site (it's strict).  Hmm.  That
seems a bit fragile.

Conclusion: inline top level things gaily until FinalPhase (the last
phase), at which point don't.

Note [pre/postInlineUnconditionally in gentle mode]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Even in gentle mode we want to do preInlineUnconditionally.  The
reason is that too little clean-up happens if you don't inline
use-once things.  Also a bit of inlining is *good* for full laziness;
it can expose constant sub-expressions.  Example in
spectral/mandel/Mandel.hs, where the mandelset function gets a useful
let-float if you inline windowToViewport

However, as usual for Gentle mode, do not inline things that are
inactive in the initial stages.  See Note [Gentle mode].

Note [Stable unfoldings and preInlineUnconditionally]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Surprisingly, do not pre-inline-unconditionally Ids with INLINE pragmas!
Example

   {-# INLINE f #-}
   f :: Eq a =&gt; a -&gt; a
   f x = ...

   fInt :: Int -&gt; Int
   fInt = f Int dEqInt

   ...fInt...fInt...fInt...

Here f occurs just once, in the RHS of fInt. But if we inline it there
it might make fInt look big, and we'll lose the opportunity to inline f
at each of fInt's call sites.  The INLINE pragma will only inline when
the application is saturated for exactly this reason; and we don't
want PreInlineUnconditionally to second-guess it.  A live example is
#3736.
    c.f. Note [Stable unfoldings and postInlineUnconditionally]

NB: if the pragma is INLINEABLE, then we don't want to behave in
this special way -- an INLINEABLE pragma just says to GHC &quot;inline this
if you like&quot;.  But if there is a unique occurrence, we want to inline
the stable unfolding, not the RHS.

Note [Top-level bottoming Ids]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Don't inline top-level Ids that are bottoming, even if they are used just
once, because FloatOut has gone to some trouble to extract them out.
Inlining them won't make the program run faster!

Note [Do not inline CoVars unconditionally]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Coercion variables appear inside coercions, and the RHS of a let-binding
is a term (not a coercion) so we can't necessarily inline the latter in
the former.
-}</span><span>
</span><span id="line-1222"></span><span>
</span><span id="line-1223"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#preInlineUnconditionally"><span class="hs-identifier hs-type">preInlineUnconditionally</span></a></span><span>
</span><span id="line-1224"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#SimplEnv"><span class="hs-identifier hs-type">SimplEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#TopLevelFlag"><span class="hs-identifier hs-type">TopLevelFlag</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#InId"><span class="hs-identifier hs-type">InId</span></a></span><span>
</span><span id="line-1225"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#InExpr"><span class="hs-identifier hs-type">InExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#StaticEnv"><span class="hs-identifier hs-type">StaticEnv</span></a></span><span>  </span><span class="hs-comment">-- These two go together</span><span>
</span><span id="line-1226"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#SimplEnv"><span class="hs-identifier hs-type">SimplEnv</span></a></span><span>       </span><span class="hs-comment">-- Returned env has extended substitution</span><span>
</span><span id="line-1227"></span><span class="hs-comment">-- Precondition: rhs satisfies the let/app invariant</span><span>
</span><span id="line-1228"></span><span class="hs-comment">-- See Note [Core let/app invariant] in GHC.Core</span><span>
</span><span id="line-1229"></span><span class="hs-comment">-- Reason: we don't want to inline single uses, or discard dead bindings,</span><span>
</span><span id="line-1230"></span><span class="hs-comment">--         for unlifted, side-effect-ful bindings</span><span>
</span><span id="line-1231"></span><span id="preInlineUnconditionally"><span class="annot"><span class="annottext">preInlineUnconditionally :: StaticEnv
-&gt; TopLevelFlag -&gt; Id -&gt; Expr Id -&gt; StaticEnv -&gt; Maybe StaticEnv
</span><a href="GHC.Core.Opt.Simplify.Utils.html#preInlineUnconditionally"><span class="hs-identifier hs-var hs-var">preInlineUnconditionally</span></a></span></span><span> </span><span id="local-6989586621680969296"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969296"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680969295"><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680969295"><span class="hs-identifier hs-var">top_lvl</span></a></span></span><span> </span><span id="local-6989586621680969294"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969294"><span class="hs-identifier hs-var">bndr</span></a></span></span><span> </span><span id="local-6989586621680969293"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969293"><span class="hs-identifier hs-var">rhs</span></a></span></span><span> </span><span id="local-6989586621680969292"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969292"><span class="hs-identifier hs-var">rhs_env</span></a></span></span><span>
</span><span id="line-1232"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969291"><span class="hs-identifier hs-var">pre_inline_unconditionally</span></a></span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe StaticEnv
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1233"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969290"><span class="hs-identifier hs-var">active</span></a></span><span>                               </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe StaticEnv
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1234"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag -&gt; Bool
</span><a href="GHC.Types.Basic.html#isTopLevel"><span class="hs-identifier hs-var">isTopLevel</span></a></span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680969295"><span class="hs-identifier hs-var">top_lvl</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Id.html#isDeadEndId"><span class="hs-identifier hs-var">isDeadEndId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969294"><span class="hs-identifier hs-var">bndr</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe StaticEnv
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-comment">-- Note [Top-level bottoming Ids]</span><span>
</span><span id="line-1235"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Var.html#isCoVar"><span class="hs-identifier hs-var">isCoVar</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969294"><span class="hs-identifier hs-var">bndr</span></a></span><span>                             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe StaticEnv
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-comment">-- Note [Do not inline CoVars unconditionally]</span><span>
</span><span id="line-1236"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#isExitJoinId"><span class="hs-identifier hs-var">isExitJoinId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969294"><span class="hs-identifier hs-var">bndr</span></a></span><span>                        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe StaticEnv
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-comment">-- Note [Do not inline exit join points]</span><span>
</span><span id="line-1237"></span><span>                                                       </span><span class="hs-comment">-- in module Exitify</span><span>
</span><span id="line-1238"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">OccInfo -&gt; Bool
</span><a href="#local-6989586621680969286"><span class="hs-identifier hs-var">one_occ</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OccInfo
</span><a href="GHC.Types.Id.html#idOccInfo"><span class="hs-identifier hs-var">idOccInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969294"><span class="hs-identifier hs-var">bndr</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe StaticEnv
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1239"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Unfolding -&gt; Bool
</span><a href="GHC.Core.html#isStableUnfolding"><span class="hs-identifier hs-var">isStableUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><a href="#local-6989586621680969284"><span class="hs-identifier hs-var">unf</span></a></span><span class="hs-special">)</span><span>              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; Maybe StaticEnv
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Expr Id -&gt; StaticEnv
</span><a href="#local-6989586621680969283"><span class="hs-identifier hs-var">extend_subst_with</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969293"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1240"></span><span>
</span><span id="line-1241"></span><span>  </span><span class="hs-comment">-- Note [Stable unfoldings and preInlineUnconditionally]</span><span>
</span><span id="line-1242"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">InlinePragma -&gt; Bool
</span><a href="GHC.Types.Basic.html#isInlinablePragma"><span class="hs-identifier hs-var">isInlinablePragma</span></a></span><span> </span><span class="annot"><span class="annottext">InlinePragma
</span><a href="#local-6989586621680969281"><span class="hs-identifier hs-var">inline_prag</span></a></span><span>
</span><span id="line-1243"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680969280"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969280"><span class="hs-identifier hs-var">inl</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Unfolding -&gt; Maybe (Expr Id)
</span><a href="GHC.Core.html#maybeUnfoldingTemplate"><span class="hs-identifier hs-var">maybeUnfoldingTemplate</span></a></span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><a href="#local-6989586621680969284"><span class="hs-identifier hs-var">unf</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; Maybe StaticEnv
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Expr Id -&gt; StaticEnv
</span><a href="#local-6989586621680969283"><span class="hs-identifier hs-var">extend_subst_with</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969280"><span class="hs-identifier hs-var">inl</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1244"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe StaticEnv
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-1245"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1246"></span><span>    </span><span id="local-6989586621680969284"><span class="annot"><span class="annottext">unf :: Unfolding
</span><a href="#local-6989586621680969284"><span class="hs-identifier hs-var hs-var">unf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Unfolding
</span><a href="GHC.Types.Id.html#idUnfolding"><span class="hs-identifier hs-var">idUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969294"><span class="hs-identifier hs-var">bndr</span></a></span><span>
</span><span id="line-1247"></span><span>    </span><span id="local-6989586621680969283"><span class="annot"><span class="annottext">extend_subst_with :: Expr Id -&gt; StaticEnv
</span><a href="#local-6989586621680969283"><span class="hs-identifier hs-var hs-var">extend_subst_with</span></a></span></span><span> </span><span id="local-6989586621680969278"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969278"><span class="hs-identifier hs-var">inl_rhs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; Id -&gt; SimplSR -&gt; StaticEnv
</span><a href="GHC.Core.Opt.Simplify.Env.html#extendIdSubst"><span class="hs-identifier hs-var">extendIdSubst</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969296"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969294"><span class="hs-identifier hs-var">bndr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StaticEnv -&gt; Expr Id -&gt; SimplSR
</span><a href="GHC.Core.Opt.Simplify.Env.html#mkContEx"><span class="hs-identifier hs-var">mkContEx</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969292"><span class="hs-identifier hs-var">rhs_env</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969278"><span class="hs-identifier hs-var">inl_rhs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1248"></span><span>
</span><span id="line-1249"></span><span>    </span><span id="local-6989586621680969286"><span class="annot"><span class="annottext">one_occ :: OccInfo -&gt; Bool
</span><a href="#local-6989586621680969286"><span class="hs-identifier hs-var hs-var">one_occ</span></a></span></span><span> </span><span class="annot"><span class="annottext">OccInfo
</span><a href="GHC.Types.Basic.html#IAmDead"><span class="hs-identifier hs-var">IAmDead</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="hs-comment">-- Happens in ((\x.1) v)</span><span>
</span><span id="line-1250"></span><span>    </span><span class="annot"><a href="#local-6989586621680969286"><span class="hs-identifier hs-var">one_occ</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#OneOcc"><span class="hs-identifier hs-type">OneOcc</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">occ_n_br :: OccInfo -&gt; Arity
</span><a href="GHC.Types.Basic.html#occ_n_br"><span class="hs-identifier hs-var">occ_n_br</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">1</span></span><span>
</span><span id="line-1251"></span><span>                  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">occ_in_lam :: OccInfo -&gt; InsideLam
</span><a href="GHC.Types.Basic.html#occ_in_lam"><span class="hs-identifier hs-var">occ_in_lam</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InsideLam
</span><a href="GHC.Types.Basic.html#NotInsideLam"><span class="hs-identifier hs-var">NotInsideLam</span></a></span><span> </span><span class="hs-special">}</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag -&gt; Bool
</span><a href="GHC.Types.Basic.html#isNotTopLevel"><span class="hs-identifier hs-var">isNotTopLevel</span></a></span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680969295"><span class="hs-identifier hs-var">top_lvl</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969264"><span class="hs-identifier hs-var">early_phase</span></a></span><span>
</span><span id="line-1252"></span><span>    </span><span class="annot"><a href="#local-6989586621680969286"><span class="hs-identifier hs-var">one_occ</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#OneOcc"><span class="hs-identifier hs-type">OneOcc</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">occ_n_br :: OccInfo -&gt; Arity
</span><a href="GHC.Types.Basic.html#occ_n_br"><span class="hs-identifier hs-var">occ_n_br</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">1</span></span><span>
</span><span id="line-1253"></span><span>                  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">occ_in_lam :: OccInfo -&gt; InsideLam
</span><a href="GHC.Types.Basic.html#occ_in_lam"><span class="hs-identifier hs-var">occ_in_lam</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InsideLam
</span><a href="GHC.Types.Basic.html#IsInsideLam"><span class="hs-identifier hs-var">IsInsideLam</span></a></span><span>
</span><span id="line-1254"></span><span>                  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">occ_int_cxt :: OccInfo -&gt; InterestingCxt
</span><a href="GHC.Types.Basic.html#occ_int_cxt"><span class="hs-identifier hs-var">occ_int_cxt</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InterestingCxt
</span><a href="GHC.Types.Basic.html#IsInteresting"><span class="hs-identifier hs-var">IsInteresting</span></a></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Bool
</span><a href="#local-6989586621680969260"><span class="hs-identifier hs-var">canInlineInLam</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969293"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-1255"></span><span>    </span><span class="annot"><a href="#local-6989586621680969286"><span class="hs-identifier hs-var">one_occ</span></a></span><span> </span><span class="annot"><span class="annottext">OccInfo
</span><span class="hs-identifier">_</span></span><span>                                     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-1256"></span><span>
</span><span id="line-1257"></span><span>    </span><span id="local-6989586621680969291"><span class="annot"><span class="annottext">pre_inline_unconditionally :: Bool
</span><a href="#local-6989586621680969291"><span class="hs-identifier hs-var hs-var">pre_inline_unconditionally</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">GeneralFlag -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#gopt"><span class="hs-identifier hs-var">gopt</span></a></span><span> </span><span class="annot"><span class="annottext">GeneralFlag
</span><a href="GHC.Driver.Flags.html#Opt_SimplPreInlining"><span class="hs-identifier hs-var">Opt_SimplPreInlining</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StaticEnv -&gt; DynFlags
</span><a href="GHC.Core.Opt.Simplify.Env.html#seDynFlags"><span class="hs-identifier hs-var">seDynFlags</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969296"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1258"></span><span>    </span><span id="local-6989586621680969257"><span class="annot"><span class="annottext">mode :: SimplMode
</span><a href="#local-6989586621680969257"><span class="hs-identifier hs-var hs-var">mode</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; SimplMode
</span><a href="GHC.Core.Opt.Simplify.Env.html#getMode"><span class="hs-identifier hs-var">getMode</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969296"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-1259"></span><span>    </span><span id="local-6989586621680969290"><span class="annot"><span class="annottext">active :: Bool
</span><a href="#local-6989586621680969290"><span class="hs-identifier hs-var hs-var">active</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CompilerPhase -&gt; Activation -&gt; Bool
</span><a href="GHC.Types.Basic.html#isActive"><span class="hs-identifier hs-var">isActive</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SimplMode -&gt; CompilerPhase
</span><a href="GHC.Core.Opt.Monad.html#sm_phase"><span class="hs-identifier hs-var hs-var">sm_phase</span></a></span><span> </span><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969257"><span class="hs-identifier hs-var">mode</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">InlinePragma -&gt; Activation
</span><a href="GHC.Types.Basic.html#inlinePragmaActivation"><span class="hs-identifier hs-var">inlinePragmaActivation</span></a></span><span> </span><span class="annot"><span class="annottext">InlinePragma
</span><a href="#local-6989586621680969281"><span class="hs-identifier hs-var">inline_prag</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1260"></span><span>             </span><span class="hs-comment">-- See Note [pre/postInlineUnconditionally in gentle mode]</span><span>
</span><span id="line-1261"></span><span>    </span><span id="local-6989586621680969281"><span class="annot"><span class="annottext">inline_prag :: InlinePragma
</span><a href="#local-6989586621680969281"><span class="hs-identifier hs-var hs-var">inline_prag</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; InlinePragma
</span><a href="GHC.Types.Id.html#idInlinePragma"><span class="hs-identifier hs-var">idInlinePragma</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969294"><span class="hs-identifier hs-var">bndr</span></a></span><span>
</span><span id="line-1262"></span><span>
</span><span id="line-1263"></span><span class="hs-comment">-- Be very careful before inlining inside a lambda, because (a) we must not</span><span>
</span><span id="line-1264"></span><span class="hs-comment">-- invalidate occurrence information, and (b) we want to avoid pushing a</span><span>
</span><span id="line-1265"></span><span class="hs-comment">-- single allocation (here) into multiple allocations (inside lambda).</span><span>
</span><span id="line-1266"></span><span class="hs-comment">-- Inlining a *function* with a single *saturated* call would be ok, mind you.</span><span>
</span><span id="line-1267"></span><span class="hs-comment">--      || (if is_cheap &amp;&amp; not (canInlineInLam rhs) then pprTrace &quot;preinline&quot; (ppr bndr &lt;+&gt; ppr rhs) ok else ok)</span><span>
</span><span id="line-1268"></span><span class="hs-comment">--      where</span><span>
</span><span id="line-1269"></span><span class="hs-comment">--              is_cheap = exprIsCheap rhs</span><span>
</span><span id="line-1270"></span><span class="hs-comment">--              ok = is_cheap &amp;&amp; int_cxt</span><span>
</span><span id="line-1271"></span><span>
</span><span id="line-1272"></span><span>        </span><span class="hs-comment">--      int_cxt         The context isn't totally boring</span><span>
</span><span id="line-1273"></span><span>        </span><span class="hs-comment">-- E.g. let f = \ab.BIG in \y. map f xs</span><span>
</span><span id="line-1274"></span><span>        </span><span class="hs-comment">--      Don't want to substitute for f, because then we allocate</span><span>
</span><span id="line-1275"></span><span>        </span><span class="hs-comment">--      its closure every time the \y is called</span><span>
</span><span id="line-1276"></span><span>        </span><span class="hs-comment">-- But: let f = \ab.BIG in \y. map (f y) xs</span><span>
</span><span id="line-1277"></span><span>        </span><span class="hs-comment">--      Now we do want to substitute for f, even though it's not</span><span>
</span><span id="line-1278"></span><span>        </span><span class="hs-comment">--      saturated, because we're going to allocate a closure for</span><span>
</span><span id="line-1279"></span><span>        </span><span class="hs-comment">--      (f y) every time round the loop anyhow.</span><span>
</span><span id="line-1280"></span><span>
</span><span id="line-1281"></span><span>        </span><span class="hs-comment">-- canInlineInLam =&gt; free vars of rhs are (Once in_lam) or Many,</span><span>
</span><span id="line-1282"></span><span>        </span><span class="hs-comment">-- so substituting rhs inside a lambda doesn't change the occ info.</span><span>
</span><span id="line-1283"></span><span>        </span><span class="hs-comment">-- Sadly, not quite the same as exprIsHNF.</span><span>
</span><span id="line-1284"></span><span>    </span><span id="local-6989586621680969260"><span class="annot"><span class="annottext">canInlineInLam :: Expr Id -&gt; Bool
</span><a href="#local-6989586621680969260"><span class="hs-identifier hs-var hs-var">canInlineInLam</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lit"><span class="hs-identifier hs-type">Lit</span></a></span><span> </span><span class="annot"><span class="annottext">Literal
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-1285"></span><span>    </span><span class="annot"><a href="#local-6989586621680969260"><span class="hs-identifier hs-var">canInlineInLam</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lam"><span class="hs-identifier hs-type">Lam</span></a></span><span> </span><span id="local-6989586621680969254"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969254"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span id="local-6989586621680969253"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969253"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Core.html#isRuntimeVar"><span class="hs-identifier hs-var">isRuntimeVar</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969254"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Bool
</span><a href="#local-6989586621680969260"><span class="hs-identifier hs-var">canInlineInLam</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969253"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-1286"></span><span>    </span><span class="annot"><a href="#local-6989586621680969260"><span class="hs-identifier hs-var">canInlineInLam</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span id="local-6989586621680969251"><span class="annot"><span class="annottext">Tickish Id
</span><a href="#local-6989586621680969251"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span id="local-6989586621680969250"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969250"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tickish Id -&gt; Bool
forall id. Tickish id -&gt; Bool
</span><a href="GHC.Core.html#tickishIsCode"><span class="hs-identifier hs-var">tickishIsCode</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><a href="#local-6989586621680969251"><span class="hs-identifier hs-var">t</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Bool
</span><a href="#local-6989586621680969260"><span class="hs-identifier hs-var">canInlineInLam</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969250"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-1287"></span><span>    </span><span class="annot"><a href="#local-6989586621680969260"><span class="hs-identifier hs-var">canInlineInLam</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><span class="hs-identifier">_</span></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-1288"></span><span>      </span><span class="hs-comment">-- not ticks.  Counting ticks cannot be duplicated, and non-counting</span><span>
</span><span id="line-1289"></span><span>      </span><span class="hs-comment">-- ticks around a Lam will disappear anyway.</span><span>
</span><span id="line-1290"></span><span>
</span><span id="line-1291"></span><span>    </span><span id="local-6989586621680969264"><span class="annot"><span class="annottext">early_phase :: Bool
</span><a href="#local-6989586621680969264"><span class="hs-identifier hs-var hs-var">early_phase</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplMode -&gt; CompilerPhase
</span><a href="GHC.Core.Opt.Monad.html#sm_phase"><span class="hs-identifier hs-var hs-var">sm_phase</span></a></span><span> </span><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969257"><span class="hs-identifier hs-var">mode</span></a></span><span> </span><span class="annot"><span class="annottext">CompilerPhase -&gt; CompilerPhase -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">/=</span></span><span> </span><span class="annot"><span class="annottext">CompilerPhase
</span><a href="GHC.Types.Basic.html#FinalPhase"><span class="hs-identifier hs-var">FinalPhase</span></a></span><span>
</span><span id="line-1292"></span><span>    </span><span class="hs-comment">-- If we don't have this early_phase test, consider</span><span>
</span><span id="line-1293"></span><span>    </span><span class="hs-comment">--      x = length [1,2,3]</span><span>
</span><span id="line-1294"></span><span>    </span><span class="hs-comment">-- The full laziness pass carefully floats all the cons cells to</span><span>
</span><span id="line-1295"></span><span>    </span><span class="hs-comment">-- top level, and preInlineUnconditionally floats them all back in.</span><span>
</span><span id="line-1296"></span><span>    </span><span class="hs-comment">-- Result is (a) static allocation replaced by dynamic allocation</span><span>
</span><span id="line-1297"></span><span>    </span><span class="hs-comment">--           (b) many simplifier iterations because this tickles</span><span>
</span><span id="line-1298"></span><span>    </span><span class="hs-comment">--               a related problem; only one inlining per pass</span><span>
</span><span id="line-1299"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-1300"></span><span>    </span><span class="hs-comment">-- On the other hand, I have seen cases where top-level fusion is</span><span>
</span><span id="line-1301"></span><span>    </span><span class="hs-comment">-- lost if we don't inline top level thing (e.g. string constants)</span><span>
</span><span id="line-1302"></span><span>    </span><span class="hs-comment">-- Hence the test for phase zero (which is the phase for all the final</span><span>
</span><span id="line-1303"></span><span>    </span><span class="hs-comment">-- simplifications).  Until phase zero we take no special notice of</span><span>
</span><span id="line-1304"></span><span>    </span><span class="hs-comment">-- top level things, but then we become more leery about inlining</span><span>
</span><span id="line-1305"></span><span>    </span><span class="hs-comment">-- them.</span><span>
</span><span id="line-1306"></span><span>
</span><span id="line-1307"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
                  postInlineUnconditionally
*                                                                      *
************************************************************************

postInlineUnconditionally
~~~~~~~~~~~~~~~~~~~~~~~~~
@postInlineUnconditionally@ decides whether to unconditionally inline
a thing based on the form of its RHS; in particular if it has a
trivial RHS.  If so, we can inline and discard the binding altogether.

NB: a loop breaker has must_keep_binding = True and non-loop-breakers
only have *forward* references. Hence, it's safe to discard the binding

NOTE: This isn't our last opportunity to inline.  We're at the binding
site right now, and we'll get another opportunity when we get to the
occurrence(s)

Note that we do this unconditional inlining only for trivial RHSs.
Don't inline even WHNFs inside lambdas; doing so may simply increase
allocation when the function is called. This isn't the last chance; see
NOTE above.

NB: Even inline pragmas (e.g. IMustBeINLINEd) are ignored here Why?
Because we don't even want to inline them into the RHS of constructor
arguments. See NOTE above

NB: At one time even NOINLINE was ignored here: if the rhs is trivial
it's best to inline it anyway.  We often get a=E; b=a from desugaring,
with both a and b marked NOINLINE.  But that seems incompatible with
our new view that inlining is like a RULE, so I'm sticking to the 'active'
story for now.

NB: unconditional inlining of this sort can introduce ticks in places that
may seem surprising; for instance, the LHS of rules. See Note [Simplfying
rules] for details.
-}</span><span>
</span><span id="line-1346"></span><span>
</span><span id="line-1347"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#postInlineUnconditionally"><span class="hs-identifier hs-type">postInlineUnconditionally</span></a></span><span>
</span><span id="line-1348"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#SimplEnv"><span class="hs-identifier hs-type">SimplEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#TopLevelFlag"><span class="hs-identifier hs-type">TopLevelFlag</span></a></span><span>
</span><span id="line-1349"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#OutId"><span class="hs-identifier hs-type">OutId</span></a></span><span>            </span><span class="hs-comment">-- The binder (*not* a CoVar), including its unfolding</span><span>
</span><span id="line-1350"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#OccInfo"><span class="hs-identifier hs-type">OccInfo</span></a></span><span>          </span><span class="hs-comment">-- From the InId</span><span>
</span><span id="line-1351"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span>
</span><span id="line-1352"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-1353"></span><span class="hs-comment">-- Precondition: rhs satisfies the let/app invariant</span><span>
</span><span id="line-1354"></span><span class="hs-comment">-- See Note [Core let/app invariant] in GHC.Core</span><span>
</span><span id="line-1355"></span><span class="hs-comment">-- Reason: we don't want to inline single uses, or discard dead bindings,</span><span>
</span><span id="line-1356"></span><span class="hs-comment">--         for unlifted, side-effect-ful bindings</span><span>
</span><span id="line-1357"></span><span id="postInlineUnconditionally"><span class="annot"><span class="annottext">postInlineUnconditionally :: StaticEnv -&gt; TopLevelFlag -&gt; Id -&gt; OccInfo -&gt; Expr Id -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#postInlineUnconditionally"><span class="hs-identifier hs-var hs-var">postInlineUnconditionally</span></a></span></span><span> </span><span id="local-6989586621680969245"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969245"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680969244"><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680969244"><span class="hs-identifier hs-var">top_lvl</span></a></span></span><span> </span><span id="local-6989586621680969243"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969243"><span class="hs-identifier hs-var">bndr</span></a></span></span><span> </span><span id="local-6989586621680969242"><span class="annot"><span class="annottext">OccInfo
</span><a href="#local-6989586621680969242"><span class="hs-identifier hs-var">occ_info</span></a></span></span><span> </span><span id="local-6989586621680969241"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969241"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-1358"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969240"><span class="hs-identifier hs-var">active</span></a></span><span>                  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-1359"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">OccInfo -&gt; Bool
</span><a href="GHC.Types.Basic.html#isWeakLoopBreaker"><span class="hs-identifier hs-var">isWeakLoopBreaker</span></a></span><span> </span><span class="annot"><span class="annottext">OccInfo
</span><a href="#local-6989586621680969242"><span class="hs-identifier hs-var">occ_info</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-comment">-- If it's a loop-breaker of any kind, don't inline</span><span>
</span><span id="line-1360"></span><span>                                        </span><span class="hs-comment">-- because it might be referred to &quot;earlier&quot;</span><span>
</span><span id="line-1361"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Unfolding -&gt; Bool
</span><a href="GHC.Core.html#isStableUnfolding"><span class="hs-identifier hs-var">isStableUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><a href="#local-6989586621680969238"><span class="hs-identifier hs-var">unfolding</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-comment">-- Note [Stable unfoldings and postInlineUnconditionally]</span><span>
</span><span id="line-1362"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag -&gt; Bool
</span><a href="GHC.Types.Basic.html#isTopLevel"><span class="hs-identifier hs-var">isTopLevel</span></a></span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680969244"><span class="hs-identifier hs-var">top_lvl</span></a></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-comment">-- Note [Top level and postInlineUnconditionally]</span><span>
</span><span id="line-1363"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Bool
</span><a href="GHC.Core.Utils.html#exprIsTrivial"><span class="hs-identifier hs-var">exprIsTrivial</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969241"><span class="hs-identifier hs-var">rhs</span></a></span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-1364"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Id.html#isJoinId"><span class="hs-identifier hs-var">isJoinId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969243"><span class="hs-identifier hs-var">bndr</span></a></span><span>                       </span><span class="hs-comment">-- See point (1) of Note [Duplicating join points]</span><span>
</span><span id="line-1365"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CompilerPhase
</span><a href="#local-6989586621680969235"><span class="hs-identifier hs-var">phase</span></a></span><span> </span><span class="annot"><span class="annottext">CompilerPhase -&gt; CompilerPhase -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">CompilerPhase
</span><a href="GHC.Types.Basic.html#FinalPhase"><span class="hs-identifier hs-var">FinalPhase</span></a></span><span class="hs-special">)</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-comment">-- in Simplify.hs</span><span>
</span><span id="line-1366"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1367"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">OccInfo
</span><a href="#local-6989586621680969242"><span class="hs-identifier hs-var">occ_info</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1368"></span><span>      </span><span class="annot"><a href="GHC.Types.Basic.html#OneOcc"><span class="hs-identifier hs-type">OneOcc</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">occ_in_lam :: OccInfo -&gt; InsideLam
</span><a href="GHC.Types.Basic.html#occ_in_lam"><span class="hs-identifier hs-var">occ_in_lam</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969234"><span class="annot"><span class="annottext">InsideLam
</span><a href="#local-6989586621680969234"><span class="hs-identifier hs-var">in_lam</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">occ_int_cxt :: OccInfo -&gt; InterestingCxt
</span><a href="GHC.Types.Basic.html#occ_int_cxt"><span class="hs-identifier hs-var">occ_int_cxt</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969233"><span class="annot"><span class="annottext">InterestingCxt
</span><a href="#local-6989586621680969233"><span class="hs-identifier hs-var">int_cxt</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">occ_n_br :: OccInfo -&gt; Arity
</span><a href="GHC.Types.Basic.html#occ_n_br"><span class="hs-identifier hs-var">occ_n_br</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680969232"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969232"><span class="hs-identifier hs-var">n_br</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1369"></span><span>        </span><span class="hs-comment">-- See Note [Inline small things to avoid creating a thunk]</span><span>
</span><span id="line-1370"></span><span>
</span><span id="line-1371"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969232"><span class="hs-identifier hs-var">n_br</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">100</span></span><span>  </span><span class="hs-comment">-- See Note [Suppress exponential blowup]</span><span>
</span><span id="line-1372"></span><span>
</span><span id="line-1373"></span><span>           </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Unfolding -&gt; Bool
</span><a href="GHC.Core.Unfold.html#smallEnoughToInline"><span class="hs-identifier hs-var">smallEnoughToInline</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969230"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><a href="#local-6989586621680969238"><span class="hs-identifier hs-var">unfolding</span></a></span><span>     </span><span class="hs-comment">-- Small enough to dup</span><span>
</span><span id="line-1374"></span><span>                        </span><span class="hs-comment">-- ToDo: consider discount on smallEnoughToInline if int_cxt is true</span><span>
</span><span id="line-1375"></span><span>                        </span><span class="hs-comment">--</span><span>
</span><span id="line-1376"></span><span>                        </span><span class="hs-comment">-- NB: Do NOT inline arbitrarily big things, even if occ_n_br=1</span><span>
</span><span id="line-1377"></span><span>                        </span><span class="hs-comment">-- Reason: doing so risks exponential behaviour.  We simplify a big</span><span>
</span><span id="line-1378"></span><span>                        </span><span class="hs-comment">--         expression, inline it, and simplify it again.  But if the</span><span>
</span><span id="line-1379"></span><span>                        </span><span class="hs-comment">--         very same thing happens in the big expression, we get</span><span>
</span><span id="line-1380"></span><span>                        </span><span class="hs-comment">--         exponential cost!</span><span>
</span><span id="line-1381"></span><span>                        </span><span class="hs-comment">-- PRINCIPLE: when we've already simplified an expression once,</span><span>
</span><span id="line-1382"></span><span>                        </span><span class="hs-comment">-- make sure that we only inline it if it's reasonably small.</span><span>
</span><span id="line-1383"></span><span>
</span><span id="line-1384"></span><span>           </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">InsideLam
</span><a href="#local-6989586621680969234"><span class="hs-identifier hs-var">in_lam</span></a></span><span> </span><span class="annot"><span class="annottext">InsideLam -&gt; InsideLam -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">InsideLam
</span><a href="GHC.Types.Basic.html#NotInsideLam"><span class="hs-identifier hs-var">NotInsideLam</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span>
</span><span id="line-1385"></span><span>                        </span><span class="hs-comment">-- Outside a lambda, we want to be reasonably aggressive</span><span>
</span><span id="line-1386"></span><span>                        </span><span class="hs-comment">-- about inlining into multiple branches of case</span><span>
</span><span id="line-1387"></span><span>                        </span><span class="hs-comment">-- e.g. let x = &lt;non-value&gt;</span><span>
</span><span id="line-1388"></span><span>                        </span><span class="hs-comment">--      in case y of { C1 -&gt; ..x..; C2 -&gt; ..x..; C3 -&gt; ... }</span><span>
</span><span id="line-1389"></span><span>                        </span><span class="hs-comment">-- Inlining can be a big win if C3 is the hot-spot, even if</span><span>
</span><span id="line-1390"></span><span>                        </span><span class="hs-comment">-- the uses in C1, C2 are not 'interesting'</span><span>
</span><span id="line-1391"></span><span>                        </span><span class="hs-comment">-- An example that gets worse if you add int_cxt here is 'clausify'</span><span>
</span><span id="line-1392"></span><span>
</span><span id="line-1393"></span><span>                </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Unfolding -&gt; Bool
</span><a href="GHC.Core.html#isCheapUnfolding"><span class="hs-identifier hs-var">isCheapUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><a href="#local-6989586621680969238"><span class="hs-identifier hs-var">unfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">InterestingCxt
</span><a href="#local-6989586621680969233"><span class="hs-identifier hs-var">int_cxt</span></a></span><span> </span><span class="annot"><span class="annottext">InterestingCxt -&gt; InterestingCxt -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">InterestingCxt
</span><a href="GHC.Types.Basic.html#IsInteresting"><span class="hs-identifier hs-var">IsInteresting</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-1394"></span><span>                        </span><span class="hs-comment">-- isCheap =&gt; acceptable work duplication; in_lam may be true</span><span>
</span><span id="line-1395"></span><span>                        </span><span class="hs-comment">-- int_cxt to prevent us inlining inside a lambda without some</span><span>
</span><span id="line-1396"></span><span>                        </span><span class="hs-comment">-- good reason.  See the notes on int_cxt in preInlineUnconditionally</span><span>
</span><span id="line-1397"></span><span>
</span><span id="line-1398"></span><span>      </span><span class="annot"><span class="annottext">OccInfo
</span><a href="GHC.Types.Basic.html#IAmDead"><span class="hs-identifier hs-var">IAmDead</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>   </span><span class="hs-comment">-- This happens; for example, the case_bndr during case of</span><span>
</span><span id="line-1399"></span><span>                        </span><span class="hs-comment">-- known constructor:  case (a,b) of x { (p,q) -&gt; ... }</span><span>
</span><span id="line-1400"></span><span>                        </span><span class="hs-comment">-- Here x isn't mentioned in the RHS, so we don't want to</span><span>
</span><span id="line-1401"></span><span>                        </span><span class="hs-comment">-- create the (dead) let-binding  let x = (a,b) in ...</span><span>
</span><span id="line-1402"></span><span>
</span><span id="line-1403"></span><span>      </span><span class="annot"><span class="annottext">OccInfo
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-1404"></span><span>
</span><span id="line-1405"></span><span class="hs-comment">-- Here's an example that we don't handle well:</span><span>
</span><span id="line-1406"></span><span class="hs-comment">--      let f = if b then Left (\x.BIG) else Right (\y.BIG)</span><span>
</span><span id="line-1407"></span><span class="hs-comment">--      in \y. ....case f of {...} ....</span><span>
</span><span id="line-1408"></span><span class="hs-comment">-- Here f is used just once, and duplicating the case work is fine (exprIsCheap).</span><span>
</span><span id="line-1409"></span><span class="hs-comment">-- But</span><span>
</span><span id="line-1410"></span><span class="hs-comment">--  - We can't preInlineUnconditionally because that would invalidate</span><span>
</span><span id="line-1411"></span><span class="hs-comment">--    the occ info for b.</span><span>
</span><span id="line-1412"></span><span class="hs-comment">--  - We can't postInlineUnconditionally because the RHS is big, and</span><span>
</span><span id="line-1413"></span><span class="hs-comment">--    that risks exponential behaviour</span><span>
</span><span id="line-1414"></span><span class="hs-comment">--  - We can't call-site inline, because the rhs is big</span><span>
</span><span id="line-1415"></span><span class="hs-comment">-- Alas!</span><span>
</span><span id="line-1416"></span><span>
</span><span id="line-1417"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1418"></span><span>    </span><span id="local-6989586621680969238"><span class="annot"><span class="annottext">unfolding :: Unfolding
</span><a href="#local-6989586621680969238"><span class="hs-identifier hs-var hs-var">unfolding</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Unfolding
</span><a href="GHC.Types.Id.html#idUnfolding"><span class="hs-identifier hs-var">idUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969243"><span class="hs-identifier hs-var">bndr</span></a></span><span>
</span><span id="line-1419"></span><span>    </span><span id="local-6989586621680969230"><span class="annot"><span class="annottext">dflags :: DynFlags
</span><a href="#local-6989586621680969230"><span class="hs-identifier hs-var hs-var">dflags</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StaticEnv -&gt; DynFlags
</span><a href="GHC.Core.Opt.Simplify.Env.html#seDynFlags"><span class="hs-identifier hs-var">seDynFlags</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969245"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-1420"></span><span>    </span><span id="local-6989586621680969235"><span class="annot"><span class="annottext">phase :: CompilerPhase
</span><a href="#local-6989586621680969235"><span class="hs-identifier hs-var hs-var">phase</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplMode -&gt; CompilerPhase
</span><a href="GHC.Core.Opt.Monad.html#sm_phase"><span class="hs-identifier hs-var hs-var">sm_phase</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StaticEnv -&gt; SimplMode
</span><a href="GHC.Core.Opt.Simplify.Env.html#getMode"><span class="hs-identifier hs-var">getMode</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969245"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1421"></span><span>    </span><span id="local-6989586621680969240"><span class="annot"><span class="annottext">active :: Bool
</span><a href="#local-6989586621680969240"><span class="hs-identifier hs-var hs-var">active</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CompilerPhase -&gt; Activation -&gt; Bool
</span><a href="GHC.Types.Basic.html#isActive"><span class="hs-identifier hs-var">isActive</span></a></span><span> </span><span class="annot"><span class="annottext">CompilerPhase
</span><a href="#local-6989586621680969235"><span class="hs-identifier hs-var">phase</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Activation
</span><a href="GHC.Types.Id.html#idInlineActivation"><span class="hs-identifier hs-var">idInlineActivation</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969243"><span class="hs-identifier hs-var">bndr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1422"></span><span>        </span><span class="hs-comment">-- See Note [pre/postInlineUnconditionally in gentle mode]</span><span>
</span><span id="line-1423"></span><span>
</span><span id="line-1424"></span><span class="hs-comment">{- Note [Inline small things to avoid creating a thunk]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The point of examining occ_info here is that for *non-values* that
occur outside a lambda, the call-site inliner won't have a chance
(because it doesn't know that the thing only occurs once).  The
pre-inliner won't have gotten it either, if the thing occurs in more
than one branch So the main target is things like

     let x = f y in
     case v of
        True  -&gt; case x of ...
        False -&gt; case x of ...

This is very important in practice; e.g. wheel-seive1 doubles
in allocation if you miss this out.  And bits of GHC itself start
to allocate more.  An egregious example is test perf/compiler/T14697,
where GHC.Driver.CmdLine.$wprocessArgs allocated hugely more.

Note [Suppress exponential blowup]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In #13253, and several related tickets, we got an exponential blowup
in code size from postInlineUnconditionally.  The trouble comes when
we have
  let j1a = case f y     of { True -&gt; p;   False -&gt; q }
      j1b = case f y     of { True -&gt; q;   False -&gt; p }
      j2a = case f (y+1) of { True -&gt; j1a; False -&gt; j1b }
      j2b = case f (y+1) of { True -&gt; j1b; False -&gt; j1a }
      ...
  in case f (y+10) of { True -&gt; j10a; False -&gt; j10b }

when there are many branches. In pass 1, postInlineUnconditionally
inlines j10a and j10b (they are both small).  Now we have two calls
to j9a and two to j9b.  In pass 2, postInlineUnconditionally inlines
all four of these calls, leaving four calls to j8a and j8b. Etc.
Yikes!  This is exponential!

A possible plan: stop doing postInlineUnconditionally
for some fixed, smallish number of branches, say 4. But that turned
out to be bad: see Note [Inline small things to avoid creating a thunk].
And, as it happened, the problem with #13253 was solved in a
different way (Note [Duplicating StrictArg] in Simplify).

So I just set an arbitrary, high limit of 100, to stop any
totally exponential behaviour.

This still leaves the nasty possiblity that /ordinary/ inlining (not
postInlineUnconditionally) might inline these join points, each of
which is individually quiet small.  I'm still not sure what to do
about this (e.g. see #15488).

Note [Top level and postInlineUnconditionally]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We don't do postInlineUnconditionally for top-level things (even for
ones that are trivial):

  * Doing so will inline top-level error expressions that have been
    carefully floated out by FloatOut.  More generally, it might
    replace static allocation with dynamic.

  * Even for trivial expressions there's a problem.  Consider
      {-# RULE &quot;foo&quot; forall (xs::[T]). reverse xs = ruggle xs #-}
      blah xs = reverse xs
      ruggle = sort
    In one simplifier pass we might fire the rule, getting
      blah xs = ruggle xs
    but in *that* simplifier pass we must not do postInlineUnconditionally
    on 'ruggle' because then we'll have an unbound occurrence of 'ruggle'

    If the rhs is trivial it'll be inlined by callSiteInline, and then
    the binding will be dead and discarded by the next use of OccurAnal

  * There is less point, because the main goal is to get rid of local
    bindings used in multiple case branches.

  * The inliner should inline trivial things at call sites anyway.

  * The Id might be exported.  We could check for that separately,
    but since we aren't going to postInlineUnconditionally /any/
    top-level bindings, we don't need to test.

Note [Stable unfoldings and postInlineUnconditionally]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do not do postInlineUnconditionally if the Id has a stable unfolding,
otherwise we lose the unfolding.  Example

     -- f has stable unfolding with rhs (e |&gt; co)
     --   where 'e' is big
     f = e |&gt; co

Then there's a danger we'll optimise to

     f' = e
     f = f' |&gt; co

and now postInlineUnconditionally, losing the stable unfolding on f.  Now f'
won't inline because 'e' is too big.

    c.f. Note [Stable unfoldings and preInlineUnconditionally]


************************************************************************
*                                                                      *
        Rebuilding a lambda
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-1530"></span><span>
</span><span id="line-1531"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkLam"><span class="hs-identifier hs-type">mkLam</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#SimplEnv"><span class="hs-identifier hs-type">SimplEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#OutBndr"><span class="hs-identifier hs-type">OutBndr</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#SimplCont"><span class="hs-identifier hs-type">SimplCont</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Monad.html#SimplM"><span class="hs-identifier hs-type">SimplM</span></a></span><span> </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span>
</span><span id="line-1532"></span><span class="hs-comment">-- mkLam tries three things</span><span>
</span><span id="line-1533"></span><span class="hs-comment">--      a) eta reduction, if that gives a trivial expression</span><span>
</span><span id="line-1534"></span><span class="hs-comment">--      b) eta expansion [only if there are some value lambdas]</span><span>
</span><span id="line-1535"></span><span>
</span><span id="line-1536"></span><span id="mkLam"><span class="annot"><span class="annottext">mkLam :: StaticEnv -&gt; [Id] -&gt; Expr Id -&gt; SimplCont -&gt; SimplM (Expr Id)
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkLam"><span class="hs-identifier hs-var hs-var">mkLam</span></a></span></span><span> </span><span id="local-6989586621680969227"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969227"><span class="hs-identifier hs-var">_env</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span id="local-6989586621680969226"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969226"><span class="hs-identifier hs-var">body</span></a></span></span><span> </span><span id="local-6989586621680969225"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969225"><span class="hs-identifier hs-var">_cont</span></a></span></span><span>
</span><span id="line-1537"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; SimplM (Expr Id)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969226"><span class="hs-identifier hs-var">body</span></a></span><span>
</span><span id="line-1538"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkLam"><span class="hs-identifier hs-var">mkLam</span></a></span><span> </span><span id="local-6989586621680969224"><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969224"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680969223"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969223"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span> </span><span id="local-6989586621680969222"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969222"><span class="hs-identifier hs-var">body</span></a></span></span><span> </span><span id="local-6989586621680969221"><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969221"><span class="hs-identifier hs-var">cont</span></a></span></span><span>
</span><span id="line-1539"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680969220"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969220"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">SimplM DynFlags
forall (m :: * -&gt; *). HasDynFlags m =&gt; m DynFlags
</span><a href="GHC.Driver.Session.html#getDynFlags"><span class="hs-identifier hs-var">getDynFlags</span></a></span><span>
</span><span id="line-1540"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; [Id] -&gt; Expr Id -&gt; SimplM (Expr Id)
</span><a href="#local-6989586621680969218"><span class="hs-identifier hs-var">mkLam'</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969220"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969223"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969222"><span class="hs-identifier hs-var">body</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1541"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1542"></span><span>    </span><span class="annot"><a href="#local-6989586621680969218"><span class="hs-identifier hs-type">mkLam'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#OutBndr"><span class="hs-identifier hs-type">OutBndr</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Monad.html#SimplM"><span class="hs-identifier hs-type">SimplM</span></a></span><span> </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span>
</span><span id="line-1543"></span><span>    </span><span id="local-6989586621680969218"><span class="annot"><span class="annottext">mkLam' :: DynFlags -&gt; [Id] -&gt; Expr Id -&gt; SimplM (Expr Id)
</span><a href="#local-6989586621680969218"><span class="hs-identifier hs-var hs-var">mkLam'</span></a></span></span><span> </span><span id="local-6989586621680969217"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969217"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680969216"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969216"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-type">Cast</span></a></span><span> </span><span id="local-6989586621680969215"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969215"><span class="hs-identifier hs-var">body</span></a></span></span><span> </span><span id="local-6989586621680969214"><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969214"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1544"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Id -&gt; Bool) -&gt; [Id] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#any"><span class="hs-identifier hs-var">any</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="#local-6989586621680969212"><span class="hs-identifier hs-var">bad</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969216"><span class="hs-identifier hs-var">bndrs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1545"></span><span>        </span><span class="hs-comment">-- Note [Casts and lambdas]</span><span>
</span><span id="line-1546"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680969211"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969211"><span class="hs-identifier hs-var">lam</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; [Id] -&gt; Expr Id -&gt; SimplM (Expr Id)
</span><a href="#local-6989586621680969218"><span class="hs-identifier hs-var">mkLam'</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969217"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969216"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969215"><span class="hs-identifier hs-var">body</span></a></span><span>
</span><span id="line-1547"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; SimplM (Expr Id)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Expr Id -&gt; OutCoercion -&gt; Expr Id
</span><a href="GHC.Core.Utils.html#mkCast"><span class="hs-identifier hs-var">mkCast</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969211"><span class="hs-identifier hs-var">lam</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Role -&gt; [Id] -&gt; OutCoercion -&gt; OutCoercion
</span><a href="GHC.Core.Coercion.html#mkPiCos"><span class="hs-identifier hs-var">mkPiCos</span></a></span><span> </span><span class="annot"><span class="annottext">Role
</span><a href="GHC.Core.Coercion.Axiom.html#Representational"><span class="hs-identifier hs-var">Representational</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969216"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969214"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1548"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-1549"></span><span>        </span><span id="local-6989586621680969208"><span class="annot"><span class="annottext">co_vars :: TyCoVarSet
</span><a href="#local-6989586621680969208"><span class="hs-identifier hs-var hs-var">co_vars</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutCoercion -&gt; TyCoVarSet
</span><a href="GHC.Core.TyCo.FVs.html#tyCoVarsOfCo"><span class="hs-identifier hs-var">tyCoVarsOfCo</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680969214"><span class="hs-identifier hs-var">co</span></a></span><span>
</span><span id="line-1550"></span><span>        </span><span id="local-6989586621680969212"><span class="annot"><span class="annottext">bad :: Id -&gt; Bool
</span><a href="#local-6989586621680969212"><span class="hs-identifier hs-var hs-var">bad</span></a></span></span><span> </span><span id="local-6989586621680969206"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969206"><span class="hs-identifier hs-var">bndr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Var.html#isCoVar"><span class="hs-identifier hs-var">isCoVar</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969206"><span class="hs-identifier hs-var">bndr</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969206"><span class="hs-identifier hs-var">bndr</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; TyCoVarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#elemVarSet"><span class="hs-operator hs-var">`elemVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">TyCoVarSet
</span><a href="#local-6989586621680969208"><span class="hs-identifier hs-var">co_vars</span></a></span><span>
</span><span id="line-1551"></span><span>
</span><span id="line-1552"></span><span>    </span><span class="annot"><a href="#local-6989586621680969218"><span class="hs-identifier hs-var">mkLam'</span></a></span><span> </span><span id="local-6989586621680969204"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969204"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680969203"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969203"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span> </span><span id="local-6989586621680969202"><span class="annot"><span class="annottext">body :: Expr Id
</span><a href="#local-6989586621680969202"><span class="hs-identifier hs-var">body</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lam"><span class="hs-identifier hs-type">Lam</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1553"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; [Id] -&gt; Expr Id -&gt; SimplM (Expr Id)
</span><a href="#local-6989586621680969218"><span class="hs-identifier hs-var">mkLam'</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969204"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969203"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; [Id] -&gt; [Id]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969201"><span class="hs-identifier hs-var">bndrs1</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969200"><span class="hs-identifier hs-var">body1</span></a></span><span>
</span><span id="line-1554"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-1555"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680969201"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969201"><span class="hs-identifier hs-var">bndrs1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969200"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969200"><span class="hs-identifier hs-var">body1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; ([Id], Expr Id)
forall b. Expr b -&gt; ([b], Expr b)
</span><a href="GHC.Core.html#collectBinders"><span class="hs-identifier hs-var">collectBinders</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969202"><span class="hs-identifier hs-var">body</span></a></span><span>
</span><span id="line-1556"></span><span>
</span><span id="line-1557"></span><span>    </span><span class="annot"><a href="#local-6989586621680969218"><span class="hs-identifier hs-var">mkLam'</span></a></span><span> </span><span id="local-6989586621680969198"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969198"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680969197"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969197"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span id="local-6989586621680969196"><span class="annot"><span class="annottext">Tickish Id
</span><a href="#local-6989586621680969196"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span id="local-6989586621680969195"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969195"><span class="hs-identifier hs-var">expr</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1558"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Tickish Id -&gt; Bool
forall id. Tickish id -&gt; Bool
</span><a href="GHC.Core.html#tickishFloatable"><span class="hs-identifier hs-var">tickishFloatable</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><a href="#local-6989586621680969196"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-1559"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tickish Id -&gt; Expr Id -&gt; Expr Id
</span><a href="GHC.Core.Utils.html#mkTick"><span class="hs-identifier hs-var">mkTick</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><a href="#local-6989586621680969196"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">(Expr Id -&gt; Expr Id) -&gt; SimplM (Expr Id) -&gt; SimplM (Expr Id)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; [Id] -&gt; Expr Id -&gt; SimplM (Expr Id)
</span><a href="#local-6989586621680969218"><span class="hs-identifier hs-var">mkLam'</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969198"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969197"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969195"><span class="hs-identifier hs-var">expr</span></a></span><span>
</span><span id="line-1560"></span><span>
</span><span id="line-1561"></span><span>    </span><span class="annot"><a href="#local-6989586621680969218"><span class="hs-identifier hs-var">mkLam'</span></a></span><span> </span><span id="local-6989586621680969191"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969191"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680969190"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969190"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span> </span><span id="local-6989586621680969189"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969189"><span class="hs-identifier hs-var">body</span></a></span></span><span>
</span><span id="line-1562"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">GeneralFlag -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#gopt"><span class="hs-identifier hs-var">gopt</span></a></span><span> </span><span class="annot"><span class="annottext">GeneralFlag
</span><a href="GHC.Driver.Flags.html#Opt_DoEtaReduction"><span class="hs-identifier hs-var">Opt_DoEtaReduction</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969191"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-1563"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680969187"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969187"><span class="hs-identifier hs-var">etad_lam</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; Expr Id -&gt; Maybe (Expr Id)
</span><a href="GHC.Core.Utils.html#tryEtaReduce"><span class="hs-identifier hs-var">tryEtaReduce</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969190"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969189"><span class="hs-identifier hs-var">body</span></a></span><span>
</span><span id="line-1564"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">Tick -&gt; SimplM ()
</span><a href="GHC.Core.Opt.Simplify.Monad.html#tick"><span class="hs-identifier hs-var">tick</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Tick
</span><a href="GHC.Core.Opt.Monad.html#EtaReduction"><span class="hs-identifier hs-var">EtaReduction</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Id] -&gt; Id
forall a. [a] -&gt; a
</span><a href="../../base/src/GHC.List.html#head"><span class="hs-identifier hs-var">head</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969190"><span class="hs-identifier hs-var">bndrs</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-1565"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; SimplM (Expr Id)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969187"><span class="hs-identifier hs-var">etad_lam</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1566"></span><span>
</span><span id="line-1567"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SimplCont -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#contIsRhs"><span class="hs-identifier hs-var">contIsRhs</span></a></span><span> </span><span class="annot"><span class="annottext">SimplCont
</span><a href="#local-6989586621680969221"><span class="hs-identifier hs-var">cont</span></a></span><span class="hs-special">)</span><span>   </span><span class="hs-comment">-- See Note [Eta-expanding lambdas]</span><span>
</span><span id="line-1568"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">SimplMode -&gt; Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_eta_expand"><span class="hs-identifier hs-var hs-var">sm_eta_expand</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StaticEnv -&gt; SimplMode
</span><a href="GHC.Core.Opt.Simplify.Env.html#getMode"><span class="hs-identifier hs-var">getMode</span></a></span><span> </span><span class="annot"><span class="annottext">StaticEnv
</span><a href="#local-6989586621680969224"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1569"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">(Id -&gt; Bool) -&gt; [Id] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#any"><span class="hs-identifier hs-var">any</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Core.html#isRuntimeVar"><span class="hs-identifier hs-var">isRuntimeVar</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969190"><span class="hs-identifier hs-var">bndrs</span></a></span><span>
</span><span id="line-1570"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680969182"><span class="annot"><span class="annottext">body_arity :: ArityType
</span><a href="#local-6989586621680969182"><span class="hs-identifier hs-var hs-var">body_arity</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Expr Id -&gt; ArityType
</span><a href="GHC.Core.Opt.Arity.html#exprEtaExpandArity"><span class="hs-identifier hs-var">exprEtaExpandArity</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969191"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969189"><span class="hs-identifier hs-var">body</span></a></span><span>
</span><span id="line-1571"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ArityType -&gt; Bool
</span><a href="GHC.Core.Opt.Arity.html#expandableArityType"><span class="hs-identifier hs-var">expandableArityType</span></a></span><span> </span><span class="annot"><span class="annottext">ArityType
</span><a href="#local-6989586621680969182"><span class="hs-identifier hs-var">body_arity</span></a></span><span>
</span><span id="line-1572"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">Tick -&gt; SimplM ()
</span><a href="GHC.Core.Opt.Simplify.Monad.html#tick"><span class="hs-identifier hs-var">tick</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Tick
</span><a href="GHC.Core.Opt.Monad.html#EtaExpansion"><span class="hs-identifier hs-var">EtaExpansion</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Id] -&gt; Id
forall a. [a] -&gt; a
</span><a href="../../base/src/GHC.List.html#head"><span class="hs-identifier hs-var">head</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969190"><span class="hs-identifier hs-var">bndrs</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-1573"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680969178"><span class="annot"><span class="annottext">res :: Expr Id
</span><a href="#local-6989586621680969178"><span class="hs-identifier hs-var hs-var">res</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; Expr Id -&gt; Expr Id
forall b. [b] -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#mkLams"><span class="hs-identifier hs-var">mkLams</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969190"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ArityType -&gt; Expr Id -&gt; Expr Id
</span><a href="GHC.Core.Opt.Arity.html#etaExpandAT"><span class="hs-identifier hs-var">etaExpandAT</span></a></span><span> </span><span class="annot"><span class="annottext">ArityType
</span><a href="#local-6989586621680969182"><span class="hs-identifier hs-var">body_arity</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969189"><span class="hs-identifier hs-var">body</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1574"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; SimplM ()
</span><a href="GHC.Core.Opt.Simplify.Monad.html#traceSmpl"><span class="hs-identifier hs-var">traceSmpl</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;eta expand&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;before&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Id] -&gt; Expr Id -&gt; Expr Id
forall b. [b] -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#mkLams"><span class="hs-identifier hs-var">mkLams</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969190"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969189"><span class="hs-identifier hs-var">body</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1575"></span><span>                                          </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;after&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969178"><span class="hs-identifier hs-var">res</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-1576"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; SimplM (Expr Id)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969178"><span class="hs-identifier hs-var">res</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1577"></span><span>
</span><span id="line-1578"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1579"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; SimplM (Expr Id)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Id] -&gt; Expr Id -&gt; Expr Id
forall b. [b] -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#mkLams"><span class="hs-identifier hs-var">mkLams</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969190"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969189"><span class="hs-identifier hs-var">body</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1580"></span><span>
</span><span id="line-1581"></span><span class="hs-comment">{-
Note [Eta expanding lambdas]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In general we *do* want to eta-expand lambdas. Consider
   f (\x -&gt; case x of (a,b) -&gt; \s -&gt; blah)
where 's' is a state token, and hence can be eta expanded.  This
showed up in the code for GHc.IO.Handle.Text.hPutChar, a rather
important function!

The eta-expansion will never happen unless we do it now.  (Well, it's
possible that CorePrep will do it, but CorePrep only has a half-baked
eta-expander that can't deal with casts.  So it's much better to do it
here.)

However, when the lambda is let-bound, as the RHS of a let, we have a
better eta-expander (in the form of tryEtaExpandRhs), so we don't
bother to try expansion in mkLam in that case; hence the contIsRhs
guard.

NB: We check the SimplEnv (sm_eta_expand), not DynFlags.
    See Note [No eta expansion in stable unfoldings]

Note [Casts and lambdas]
~~~~~~~~~~~~~~~~~~~~~~~~
Consider
        (\x. (\y. e) `cast` g1) `cast` g2
There is a danger here that the two lambdas look separated, and the
full laziness pass might float an expression to between the two.

So this equation in mkLam' floats the g1 out, thus:
        (\x. e `cast` g1)  --&gt;  (\x.e) `cast` (tx -&gt; g1)
where x:tx.

In general, this floats casts outside lambdas, where (I hope) they
might meet and cancel with some other cast:
        \x. e `cast` co   ===&gt;   (\x. e) `cast` (tx -&gt; co)
        /\a. e `cast` co  ===&gt;   (/\a. e) `cast` (/\a. co)
        /\g. e `cast` co  ===&gt;   (/\g. e) `cast` (/\g. co)
                          (if not (g `in` co))

Notice that it works regardless of 'e'.  Originally it worked only
if 'e' was itself a lambda, but in some cases that resulted in
fruitless iteration in the simplifier.  A good example was when
compiling Text.ParserCombinators.ReadPrec, where we had a definition
like    (\x. Get `cast` g)
where Get is a constructor with nonzero arity.  Then mkLam eta-expanded
the Get, and the next iteration eta-reduced it, and then eta-expanded
it again.

Note also the side condition for the case of coercion binders.
It does not make sense to transform
        /\g. e `cast` g  ==&gt;  (/\g.e) `cast` (/\g.g)
because the latter is not well-kinded.

************************************************************************
*                                                                      *
              Eta expansion
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-1641"></span><span>
</span><span id="line-1642"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#tryEtaExpandRhs"><span class="hs-identifier hs-type">tryEtaExpandRhs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Monad.html#SimplMode"><span class="hs-identifier hs-type">SimplMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#OutId"><span class="hs-identifier hs-type">OutId</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span>
</span><span id="line-1643"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Monad.html#SimplM"><span class="hs-identifier hs-type">SimplM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.Arity.html#ArityType"><span class="hs-identifier hs-type">ArityType</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1644"></span><span class="hs-comment">-- See Note [Eta-expanding at let bindings]</span><span>
</span><span id="line-1645"></span><span class="hs-comment">-- If tryEtaExpandRhs rhs = (n, is_bot, rhs') then</span><span>
</span><span id="line-1646"></span><span class="hs-comment">--   (a) rhs' has manifest arity n</span><span>
</span><span id="line-1647"></span><span class="hs-comment">--   (b) if is_bot is True then rhs' applied to n args is guaranteed bottom</span><span>
</span><span id="line-1648"></span><span id="tryEtaExpandRhs"><span class="annot"><span class="annottext">tryEtaExpandRhs :: SimplMode -&gt; Id -&gt; Expr Id -&gt; SimplM (ArityType, Expr Id)
</span><a href="GHC.Core.Opt.Simplify.Utils.html#tryEtaExpandRhs"><span class="hs-identifier hs-var hs-var">tryEtaExpandRhs</span></a></span></span><span> </span><span id="local-6989586621680969174"><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969174"><span class="hs-identifier hs-var">mode</span></a></span></span><span> </span><span id="local-6989586621680969173"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969173"><span class="hs-identifier hs-var">bndr</span></a></span></span><span> </span><span id="local-6989586621680969172"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969172"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-1649"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680969171"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969171"><span class="hs-identifier hs-var">join_arity</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Maybe Arity
</span><a href="GHC.Types.Id.html#isJoinId_maybe"><span class="hs-identifier hs-var">isJoinId_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969173"><span class="hs-identifier hs-var">bndr</span></a></span><span>
</span><span id="line-1650"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680969169"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969169"><span class="hs-identifier hs-var">join_bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969168"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969168"><span class="hs-identifier hs-var">join_body</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Expr Id -&gt; ([Id], Expr Id)
forall b. Arity -&gt; Expr b -&gt; ([b], Expr b)
</span><a href="GHC.Core.html#collectNBinders"><span class="hs-identifier hs-var">collectNBinders</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969171"><span class="hs-identifier hs-var">join_arity</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969172"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-1651"></span><span>             </span><span id="local-6989586621680969166"><span class="annot"><span class="annottext">oss :: [OneShotInfo]
</span><a href="#local-6989586621680969166"><span class="hs-identifier hs-var hs-var">oss</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Id -&gt; OneShotInfo
</span><a href="GHC.Types.Id.html#idOneShotInfo"><span class="hs-identifier hs-var">idOneShotInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969164"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680969164"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969164"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969169"><span class="hs-identifier hs-var">join_bndrs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Var.html#isId"><span class="hs-identifier hs-var">isId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969164"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1652"></span><span>             </span><span id="local-6989586621680969161"><span class="annot"><span class="annottext">arity_type :: ArityType
</span><a href="#local-6989586621680969161"><span class="hs-identifier hs-var hs-var">arity_type</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Bool
</span><a href="GHC.Core.Utils.html#exprIsDeadEnd"><span class="hs-identifier hs-var">exprIsDeadEnd</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969168"><span class="hs-identifier hs-var">join_body</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; ArityType
</span><a href="GHC.Core.Opt.Arity.html#ABot"><span class="hs-identifier hs-var">ABot</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[OneShotInfo] -&gt; Arity
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Arity
</span><a href="../../base/src/Data.Foldable.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[OneShotInfo]
</span><a href="#local-6989586621680969166"><span class="hs-identifier hs-var">oss</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1653"></span><span>                        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>               </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[OneShotInfo] -&gt; ArityType
</span><a href="GHC.Core.Opt.Arity.html#ATop"><span class="hs-identifier hs-var">ATop</span></a></span><span> </span><span class="annot"><span class="annottext">[OneShotInfo]
</span><a href="#local-6989586621680969166"><span class="hs-identifier hs-var">oss</span></a></span><span>
</span><span id="line-1654"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(ArityType, Expr Id) -&gt; SimplM (ArityType, Expr Id)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ArityType
</span><a href="#local-6989586621680969161"><span class="hs-identifier hs-var">arity_type</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969172"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1655"></span><span>         </span><span class="hs-comment">-- Note [Do not eta-expand join points]</span><span>
</span><span id="line-1656"></span><span>         </span><span class="hs-comment">-- But do return the correct arity and bottom-ness, because</span><span>
</span><span id="line-1657"></span><span>         </span><span class="hs-comment">-- these are used to set the bndr's IdInfo (#15517)</span><span>
</span><span id="line-1658"></span><span>         </span><span class="hs-comment">-- Note [Invariants on join points] invariant 2b, in GHC.Core</span><span>
</span><span id="line-1659"></span><span>
</span><span id="line-1660"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">SimplMode -&gt; Bool
</span><a href="GHC.Core.Opt.Monad.html#sm_eta_expand"><span class="hs-identifier hs-var hs-var">sm_eta_expand</span></a></span><span> </span><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969174"><span class="hs-identifier hs-var">mode</span></a></span><span>      </span><span class="hs-comment">-- Provided eta-expansion is on</span><span>
</span><span id="line-1661"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969156"><span class="hs-identifier hs-var">new_arity</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969155"><span class="hs-identifier hs-var">old_arity</span></a></span><span>   </span><span class="hs-comment">-- And the current manifest arity isn't enough</span><span>
</span><span id="line-1662"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Bool
</span><a href="#local-6989586621680969154"><span class="hs-identifier hs-var">want_eta</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969172"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-1663"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">Tick -&gt; SimplM ()
</span><a href="GHC.Core.Opt.Simplify.Monad.html#tick"><span class="hs-identifier hs-var">tick</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Tick
</span><a href="GHC.Core.Opt.Monad.html#EtaExpansion"><span class="hs-identifier hs-var">EtaExpansion</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969173"><span class="hs-identifier hs-var">bndr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1664"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(ArityType, Expr Id) -&gt; SimplM (ArityType, Expr Id)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ArityType
</span><a href="#local-6989586621680969153"><span class="hs-identifier hs-var">arity_type</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ArityType -&gt; Expr Id -&gt; Expr Id
</span><a href="GHC.Core.Opt.Arity.html#etaExpandAT"><span class="hs-identifier hs-var">etaExpandAT</span></a></span><span> </span><span class="annot"><span class="annottext">ArityType
</span><a href="#local-6989586621680969153"><span class="hs-identifier hs-var">arity_type</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969172"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1665"></span><span>
</span><span id="line-1666"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1667"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(ArityType, Expr Id) -&gt; SimplM (ArityType, Expr Id)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ArityType
</span><a href="#local-6989586621680969153"><span class="hs-identifier hs-var">arity_type</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969172"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1668"></span><span>
</span><span id="line-1669"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1670"></span><span>    </span><span id="local-6989586621680969152"><span class="annot"><span class="annottext">dflags :: DynFlags
</span><a href="#local-6989586621680969152"><span class="hs-identifier hs-var hs-var">dflags</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SimplMode -&gt; DynFlags
</span><a href="GHC.Core.Opt.Monad.html#sm_dflags"><span class="hs-identifier hs-var hs-var">sm_dflags</span></a></span><span> </span><span class="annot"><span class="annottext">SimplMode
</span><a href="#local-6989586621680969174"><span class="hs-identifier hs-var">mode</span></a></span><span>
</span><span id="line-1671"></span><span>    </span><span id="local-6989586621680969155"><span class="annot"><span class="annottext">old_arity :: Arity
</span><a href="#local-6989586621680969155"><span class="hs-identifier hs-var hs-var">old_arity</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Arity
</span><a href="GHC.Core.Opt.Arity.html#exprArity"><span class="hs-identifier hs-var">exprArity</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969172"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-1672"></span><span>
</span><span id="line-1673"></span><span>    </span><span id="local-6989586621680969153"><span class="annot"><span class="annottext">arity_type :: ArityType
</span><a href="#local-6989586621680969153"><span class="hs-identifier hs-var hs-var">arity_type</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Id -&gt; Expr Id -&gt; Arity -&gt; ArityType
</span><a href="GHC.Core.Opt.Arity.html#findRhsArity"><span class="hs-identifier hs-var">findRhsArity</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969152"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969173"><span class="hs-identifier hs-var">bndr</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969172"><span class="hs-identifier hs-var">rhs</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680969155"><span class="hs-identifier hs-var">old_arity</span></a></span><span>
</span><span id="line-1674"></span><span>                 </span><span class="annot"><span class="annottext">ArityType -&gt; Arity -&gt; ArityType
</span><a href="GHC.Core.Opt.Arity.html#maxWithArity"><span class="hs-operator hs-var">`maxWithArity`</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Arity
</span><a href="GHC.Types.Id.html#idCallArity"><span class="hs-identifier hs-var">idCallArity</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969173"><span class="hs-identifier hs-var">bndr</span></a></span><span>
</span><span id="line-1675"></span><span>    </span><span id="local-6989586621680969156"><span class="annot"><span class="annottext">new_arity :: Arity
</span><a href="#local-6989586621680969156"><span class="hs-identifier hs-var hs-var">new_arity</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ArityType -&gt; Arity
</span><a href="GHC.Core.Opt.Arity.html#arityTypeArity"><span class="hs-identifier hs-var">arityTypeArity</span></a></span><span> </span><span class="annot"><span class="annottext">ArityType
</span><a href="#local-6989586621680969153"><span class="hs-identifier hs-var">arity_type</span></a></span><span>
</span><span id="line-1676"></span><span>
</span><span id="line-1677"></span><span>    </span><span class="hs-comment">-- See Note [Which RHSs do we eta-expand?]</span><span>
</span><span id="line-1678"></span><span>    </span><span id="local-6989586621680969154"><span class="annot"><span class="annottext">want_eta :: Expr Id -&gt; Bool
</span><a href="#local-6989586621680969154"><span class="hs-identifier hs-var hs-var">want_eta</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-type">Cast</span></a></span><span> </span><span id="local-6989586621680969146"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969146"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>                  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Bool
</span><a href="#local-6989586621680969154"><span class="hs-identifier hs-var">want_eta</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969146"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-1679"></span><span>    </span><span class="annot"><a href="#local-6989586621680969154"><span class="hs-identifier hs-var">want_eta</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969145"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969145"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span>                  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Bool
</span><a href="#local-6989586621680969154"><span class="hs-identifier hs-var">want_eta</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969145"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-1680"></span><span>    </span><span class="annot"><a href="#local-6989586621680969154"><span class="hs-identifier hs-var">want_eta</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lam"><span class="hs-identifier hs-type">Lam</span></a></span><span> </span><span id="local-6989586621680969144"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969144"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span id="local-6989586621680969143"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969143"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Var.html#isTyVar"><span class="hs-identifier hs-var">isTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969144"><span class="hs-identifier hs-var">b</span></a></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Bool
</span><a href="#local-6989586621680969154"><span class="hs-identifier hs-var">want_eta</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969143"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-1681"></span><span>    </span><span class="annot"><a href="#local-6989586621680969154"><span class="hs-identifier hs-var">want_eta</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680969142"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969142"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span id="local-6989586621680969141"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969141"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Bool
</span><a href="GHC.Core.Utils.html#exprIsTrivial"><span class="hs-identifier hs-var">exprIsTrivial</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969141"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Bool
</span><a href="#local-6989586621680969154"><span class="hs-identifier hs-var">want_eta</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969142"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-1682"></span><span>    </span><span class="annot"><a href="#local-6989586621680969154"><span class="hs-identifier hs-var">want_eta</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>                    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-1683"></span><span>    </span><span class="annot"><a href="#local-6989586621680969154"><span class="hs-identifier hs-var">want_eta</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lit"><span class="hs-identifier hs-type">Lit</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">)</span><span>                    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-1684"></span><span>    </span><span class="annot"><a href="#local-6989586621680969154"><span class="hs-identifier hs-var">want_eta</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-1685"></span><span class="hs-comment">{-
    want_eta _ = case arity_type of
                   ATop (os:_) -&gt; isOneShotInfo os
                   ATop []     -&gt; False
                   ABot {}     -&gt; True
-}</span><span>
</span><span id="line-1691"></span><span>
</span><span id="line-1692"></span><span class="hs-comment">{-
Note [Eta-expanding at let bindings]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We now eta expand at let-bindings, which is where the payoff comes.
The most significant thing is that we can do a simple arity analysis
(in GHC.Core.Opt.Arity.findRhsArity), which we can't do for free-floating lambdas

One useful consequence of not eta-expanding lambdas is this example:
   genMap :: C a =&gt; ...
   {-# INLINE genMap #-}
   genMap f xs = ...

   myMap :: D a =&gt; ...
   {-# INLINE myMap #-}
   myMap = genMap

Notice that 'genMap' should only inline if applied to two arguments.
In the stable unfolding for myMap we'll have the unfolding
    (\d -&gt; genMap Int (..d..))
We do not want to eta-expand to
    (\d f xs -&gt; genMap Int (..d..) f xs)
because then 'genMap' will inline, and it really shouldn't: at least
as far as the programmer is concerned, it's not applied to two
arguments!

Note [Which RHSs do we eta-expand?]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We don't eta-expand:

* Trivial RHSs, e.g.     f = g
  If we eta expand do
    f = \x. g x
  we'll just eta-reduce again, and so on; so the
  simplifier never terminates.

* PAPs: see Note [Do not eta-expand PAPs]

What about things like this?
   f = case y of p -&gt; \x -&gt; blah

Here we do eta-expand.  This is a change (Jun 20), but if we have
really decided that f has arity 1, then putting that lambda at the top
seems like a Good idea.

Note [Do not eta-expand PAPs]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We used to have old_arity = manifestArity rhs, which meant that we
would eta-expand even PAPs.  But this gives no particular advantage,
and can lead to a massive blow-up in code size, exhibited by #9020.
Suppose we have a PAP
    foo :: IO ()
    foo = returnIO ()
Then we can eta-expand do
    foo = (\eta. (returnIO () |&gt; sym g) eta) |&gt; g
where
    g :: IO () ~ State# RealWorld -&gt; (# State# RealWorld, () #)

But there is really no point in doing this, and it generates masses of
coercions and whatnot that eventually disappear again. For T9020, GHC
allocated 6.6G before, and 0.8G afterwards; and residency dropped from
1.8G to 45M.

Moreover, if we eta expand
        f = g d  ==&gt;  f = \x. g d x
that might in turn make g inline (if it has an inline pragma), which
we might not want.  After all, INLINE pragmas say &quot;inline only when
saturated&quot; so we don't want to be too gung-ho about saturating!

But note that this won't eta-expand, say
  f = \g -&gt; map g
Does it matter not eta-expanding such functions?  I'm not sure.  Perhaps
strictness analysis will have less to bite on?

Note [Do not eta-expand join points]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Similarly to CPR (see Note [Don't w/w join points for CPR] in
GHC.Core.Opt.WorkWrap), a join point stands well to gain from its outer binding's
eta-expansion, and eta-expanding a join point is fraught with issues like how to
deal with a cast:

    let join $j1 :: IO ()
             $j1 = ...
             $j2 :: Int -&gt; IO ()
             $j2 n = if n &gt; 0 then $j1
                              else ...

    =&gt;

    let join $j1 :: IO ()
             $j1 = (\eta -&gt; ...)
                     `cast` N:IO :: State# RealWorld -&gt; (# State# RealWorld, ())
                                 ~  IO ()
             $j2 :: Int -&gt; IO ()
             $j2 n = (\eta -&gt; if n &gt; 0 then $j1
                                       else ...)
                     `cast` N:IO :: State# RealWorld -&gt; (# State# RealWorld, ())
                                 ~  IO ()

The cast here can't be pushed inside the lambda (since it's not casting to a
function type), so the lambda has to stay, but it can't because it contains a
reference to a join point. In fact, $j2 can't be eta-expanded at all. Rather
than try and detect this situation (and whatever other situations crop up!), we
don't bother; again, any surrounding eta-expansion will improve these join
points anyway, since an outer cast can *always* be pushed inside. By the time
CorePrep comes around, the code is very likely to look more like this:

    let join $j1 :: State# RealWorld -&gt; (# State# RealWorld, ())
             $j1 = (...) eta
             $j2 :: Int -&gt; State# RealWorld -&gt; (# State# RealWorld, ())
             $j2 = if n &gt; 0 then $j1
                            else (...) eta


************************************************************************
*                                                                      *
\subsection{Floating lets out of big lambdas}
*                                                                      *
************************************************************************

Note [Floating and type abstraction]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider this:
        x = /\a. C e1 e2
We'd like to float this to
        y1 = /\a. e1
        y2 = /\a. e2
        x  = /\a. C (y1 a) (y2 a)
for the usual reasons: we want to inline x rather vigorously.

You may think that this kind of thing is rare.  But in some programs it is
common.  For example, if you do closure conversion you might get:

        data a :-&gt; b = forall e. (e -&gt; a -&gt; b) :$ e

        f_cc :: forall a. a :-&gt; a
        f_cc = /\a. (\e. id a) :$ ()

Now we really want to inline that f_cc thing so that the
construction of the closure goes away.

So I have elaborated simplLazyBind to understand right-hand sides that look
like
        /\ a1..an. body

and treat them specially. The real work is done in
GHC.Core.Opt.Simplify.Utils.abstractFloats, but there is quite a bit of plumbing
in simplLazyBind as well.

The same transformation is good when there are lets in the body:

        /\abc -&gt; let(rec) x = e in b
   ==&gt;
        let(rec) x' = /\abc -&gt; let x = x' a b c in e
        in
        /\abc -&gt; let x = x' a b c in b

This is good because it can turn things like:

        let f = /\a -&gt; letrec g = ... g ... in g
into
        letrec g' = /\a -&gt; ... g' a ...
        in
        let f = /\ a -&gt; g' a

which is better.  In effect, it means that big lambdas don't impede
let-floating.

This optimisation is CRUCIAL in eliminating the junk introduced by
desugaring mutually recursive definitions.  Don't eliminate it lightly!

[May 1999]  If we do this transformation *regardless* then we can
end up with some pretty silly stuff.  For example,

        let
            st = /\ s -&gt; let { x1=r1 ; x2=r2 } in ...
        in ..
becomes
        let y1 = /\s -&gt; r1
            y2 = /\s -&gt; r2
            st = /\s -&gt; ...[y1 s/x1, y2 s/x2]
        in ..

Unless the &quot;...&quot; is a WHNF there is really no point in doing this.
Indeed it can make things worse.  Suppose x1 is used strictly,
and is of the form

        x1* = case f y of { (a,b) -&gt; e }

If we abstract this wrt the tyvar we then can't do the case inline
as we would normally do.

That's why the whole transformation is part of the same process that
floats let-bindings and constructor arguments out of RHSs.  In particular,
it is guarded by the doFloatFromRhs call in simplLazyBind.

Note [Which type variables to abstract over]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Abstract only over the type variables free in the rhs wrt which the
new binding is abstracted.  Note that

  * The naive approach of abstracting wrt the
    tyvars free in the Id's /type/ fails. Consider:
        /\ a b -&gt; let t :: (a,b) = (e1, e2)
                      x :: a     = fst t
                  in ...
    Here, b isn't free in x's type, but we must nevertheless
    abstract wrt b as well, because t's type mentions b.
    Since t is floated too, we'd end up with the bogus:
         poly_t = /\ a b -&gt; (e1, e2)
         poly_x = /\ a   -&gt; fst (poly_t a *b*)

  * We must do closeOverKinds.  Example (#10934):
       f = /\k (f:k-&gt;*) (a:k). let t = AccFailure @ (f a) in ...
    Here we want to float 't', but we must remember to abstract over
    'k' as well, even though it is not explicitly mentioned in the RHS,
    otherwise we get
       t = /\ (f:k-&gt;*) (a:k). AccFailure @ (f a)
    which is obviously bogus.
-}</span><span>
</span><span id="line-1911"></span><span>
</span><span id="line-1912"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#abstractFloats"><span class="hs-identifier hs-type">abstractFloats</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#TopLevelFlag"><span class="hs-identifier hs-type">TopLevelFlag</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#OutTyVar"><span class="hs-identifier hs-type">OutTyVar</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Env.html#SimplFloats"><span class="hs-identifier hs-type">SimplFloats</span></a></span><span>
</span><span id="line-1913"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Monad.html#SimplM"><span class="hs-identifier hs-type">SimplM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#OutBind"><span class="hs-identifier hs-type">OutBind</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1914"></span><span id="abstractFloats"><span class="annot"><span class="annottext">abstractFloats :: DynFlags
-&gt; TopLevelFlag
-&gt; [Id]
-&gt; SimplFloats
-&gt; Expr Id
-&gt; SimplM ([Bind Id], Expr Id)
</span><a href="GHC.Core.Opt.Simplify.Utils.html#abstractFloats"><span class="hs-identifier hs-var hs-var">abstractFloats</span></a></span></span><span> </span><span id="local-6989586621680969138"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969138"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680969137"><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680969137"><span class="hs-identifier hs-var">top_lvl</span></a></span></span><span> </span><span id="local-6989586621680969136"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969136"><span class="hs-identifier hs-var">main_tvs</span></a></span></span><span> </span><span id="local-6989586621680969135"><span class="annot"><span class="annottext">SimplFloats
</span><a href="#local-6989586621680969135"><span class="hs-identifier hs-var">floats</span></a></span></span><span> </span><span id="local-6989586621680969134"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969134"><span class="hs-identifier hs-var">body</span></a></span></span><span>
</span><span id="line-1915"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">notNull</span><span> </span><span class="hs-identifier">body_floats</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-1916"></span><span>    </span><span class="hs-identifier">ASSERT</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">isNilOL</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">sfJoinFloats</span><span> </span><span class="hs-identifier">floats</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-1917"></span><span>    </span><span class="hs-keyword">do</span><span>  </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680969129"><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680969129"><span class="hs-identifier hs-var">subst</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969128"><span class="annot"><span class="annottext">[Bind Id]
</span><a href="#local-6989586621680969128"><span class="hs-identifier hs-var">float_binds</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(Subst -&gt; Bind Id -&gt; SimplM (Subst, Bind Id))
-&gt; Subst -&gt; [Bind Id] -&gt; SimplM (Subst, [Bind Id])
forall (m :: * -&gt; *) acc x y.
Monad m =&gt;
(acc -&gt; x -&gt; m (acc, y)) -&gt; acc -&gt; [x] -&gt; m (acc, [y])
</span><a href="GHC.Utils.Monad.html#mapAccumLM"><span class="hs-identifier hs-var">mapAccumLM</span></a></span><span> </span><span class="annot"><span class="annottext">Subst -&gt; Bind Id -&gt; SimplM (Subst, Bind Id)
</span><a href="#local-6989586621680969126"><span class="hs-identifier hs-var">abstract</span></a></span><span> </span><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680969125"><span class="hs-identifier hs-var">empty_subst</span></a></span><span> </span><span class="annot"><span class="annottext">[Bind Id]
</span><a href="#local-6989586621680969132"><span class="hs-identifier hs-var">body_floats</span></a></span><span>
</span><span id="line-1918"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">([Bind Id], Expr Id) -&gt; SimplM ([Bind Id], Expr Id)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Bind Id]
</span><a href="#local-6989586621680969128"><span class="hs-identifier hs-var">float_binds</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Subst -&gt; Expr Id -&gt; Expr Id
Subst -&gt; Expr Id -&gt; Expr Id
</span><a href="GHC.Core.Subst.html#substExpr"><span class="hs-identifier hs-var">GHC.Core.Subst.substExpr</span></a></span><span> </span><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680969129"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969134"><span class="hs-identifier hs-var">body</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1919"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1920"></span><span>    </span><span id="local-6989586621680969123"><span class="annot"><span class="annottext">is_top_lvl :: Bool
</span><a href="#local-6989586621680969123"><span class="hs-identifier hs-var hs-var">is_top_lvl</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag -&gt; Bool
</span><a href="GHC.Types.Basic.html#isTopLevel"><span class="hs-identifier hs-var">isTopLevel</span></a></span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680969137"><span class="hs-identifier hs-var">top_lvl</span></a></span><span>
</span><span id="line-1921"></span><span>    </span><span id="local-6989586621680969122"><span class="annot"><span class="annottext">main_tv_set :: TyCoVarSet
</span><a href="#local-6989586621680969122"><span class="hs-identifier hs-var hs-var">main_tv_set</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; TyCoVarSet
</span><a href="GHC.Types.Var.Set.html#mkVarSet"><span class="hs-identifier hs-var">mkVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969136"><span class="hs-identifier hs-var">main_tvs</span></a></span><span>
</span><span id="line-1922"></span><span>    </span><span id="local-6989586621680969132"><span class="annot"><span class="annottext">body_floats :: [Bind Id]
</span><a href="#local-6989586621680969132"><span class="hs-identifier hs-var hs-var">body_floats</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">LetFloats -&gt; [Bind Id]
</span><a href="GHC.Core.Opt.Simplify.Env.html#letFloatBinds"><span class="hs-identifier hs-var">letFloatBinds</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SimplFloats -&gt; LetFloats
</span><a href="GHC.Core.Opt.Simplify.Env.html#sfLetFloats"><span class="hs-identifier hs-var hs-var">sfLetFloats</span></a></span><span> </span><span class="annot"><span class="annottext">SimplFloats
</span><a href="#local-6989586621680969135"><span class="hs-identifier hs-var">floats</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1923"></span><span>    </span><span id="local-6989586621680969125"><span class="annot"><span class="annottext">empty_subst :: Subst
</span><a href="#local-6989586621680969125"><span class="hs-identifier hs-var hs-var">empty_subst</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; Subst
</span><a href="GHC.Core.Subst.html#mkEmptySubst"><span class="hs-identifier hs-var">GHC.Core.Subst.mkEmptySubst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SimplFloats -&gt; InScopeSet
</span><a href="GHC.Core.Opt.Simplify.Env.html#sfInScope"><span class="hs-identifier hs-var hs-var">sfInScope</span></a></span><span> </span><span class="annot"><span class="annottext">SimplFloats
</span><a href="#local-6989586621680969135"><span class="hs-identifier hs-var">floats</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1924"></span><span>
</span><span id="line-1925"></span><span>    </span><span class="annot"><a href="#local-6989586621680969126"><span class="hs-identifier hs-type">abstract</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Subst.html#Subst"><span class="hs-identifier hs-type">GHC.Core.Subst.Subst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutBind"><span class="hs-identifier hs-type">OutBind</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Monad.html#SimplM"><span class="hs-identifier hs-type">SimplM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Subst.html#Subst"><span class="hs-identifier hs-type">GHC.Core.Subst.Subst</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#OutBind"><span class="hs-identifier hs-type">OutBind</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1926"></span><span>    </span><span id="local-6989586621680969126"><span class="annot"><span class="annottext">abstract :: Subst -&gt; Bind Id -&gt; SimplM (Subst, Bind Id)
</span><a href="#local-6989586621680969126"><span class="hs-identifier hs-var hs-var">abstract</span></a></span></span><span> </span><span id="local-6989586621680969116"><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680969116"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#NonRec"><span class="hs-identifier hs-type">NonRec</span></a></span><span> </span><span id="local-6989586621680969114"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969114"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span id="local-6989586621680969113"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969113"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1927"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680969112"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969112"><span class="hs-identifier hs-var">poly_id1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969111"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969111"><span class="hs-identifier hs-var">poly_app</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; Id -&gt; SimplM (Id, Expr Id)
</span><a href="#local-6989586621680969110"><span class="hs-identifier hs-var">mk_poly1</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969109"><span class="hs-identifier hs-var">tvs_here</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969114"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-1928"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680969108"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969108"><span class="hs-identifier hs-var">poly_id2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969107"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969107"><span class="hs-identifier hs-var">poly_rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; [Id] -&gt; Expr Id -&gt; (Id, Expr Id)
</span><a href="#local-6989586621680969106"><span class="hs-identifier hs-var">mk_poly2</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969112"><span class="hs-identifier hs-var">poly_id1</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969109"><span class="hs-identifier hs-var">tvs_here</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969105"><span class="hs-identifier hs-var">rhs'</span></a></span><span>
</span><span id="line-1929"></span><span>                 </span><span id="local-6989586621680969104"><span class="annot"><span class="annottext">subst' :: Subst
</span><a href="#local-6989586621680969104"><span class="hs-identifier hs-var hs-var">subst'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Subst -&gt; Id -&gt; Expr Id -&gt; Subst
</span><a href="GHC.Core.Subst.html#extendIdSubst"><span class="hs-identifier hs-var">GHC.Core.Subst.extendIdSubst</span></a></span><span> </span><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680969116"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969114"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969111"><span class="hs-identifier hs-var">poly_app</span></a></span><span>
</span><span id="line-1930"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(Subst, Bind Id) -&gt; SimplM (Subst, Bind Id)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680969104"><span class="hs-identifier hs-var">subst'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Expr Id -&gt; Bind Id
forall b. b -&gt; Expr b -&gt; Bind b
</span><a href="GHC.Core.html#NonRec"><span class="hs-identifier hs-var">NonRec</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969108"><span class="hs-identifier hs-var">poly_id2</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969107"><span class="hs-identifier hs-var">poly_rhs</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1931"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-1932"></span><span>        </span><span id="local-6989586621680969105"><span class="annot"><span class="annottext">rhs' :: Expr Id
</span><a href="#local-6989586621680969105"><span class="hs-identifier hs-var hs-var">rhs'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Subst -&gt; Expr Id -&gt; Expr Id
Subst -&gt; Expr Id -&gt; Expr Id
</span><a href="GHC.Core.Subst.html#substExpr"><span class="hs-identifier hs-var">GHC.Core.Subst.substExpr</span></a></span><span> </span><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680969116"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969113"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-1933"></span><span>
</span><span id="line-1934"></span><span>        </span><span class="hs-comment">-- tvs_here: see Note [Which type variables to abstract over]</span><span>
</span><span id="line-1935"></span><span>        </span><span id="local-6989586621680969109"><span class="annot"><span class="annottext">tvs_here :: [Id]
</span><a href="#local-6989586621680969109"><span class="hs-identifier hs-var hs-var">tvs_here</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; [Id]
</span><a href="GHC.Core.TyCo.FVs.html#scopedSort"><span class="hs-identifier hs-var">scopedSort</span></a></span><span> </span><span class="annot"><span class="annottext">([Id] -&gt; [Id]) -&gt; [Id] -&gt; [Id]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1936"></span><span>                   </span><span class="annot"><span class="annottext">(Id -&gt; Bool) -&gt; [Id] -&gt; [Id]
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#filter"><span class="hs-identifier hs-var">filter</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; TyCoVarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#elemVarSet"><span class="hs-operator hs-var">`elemVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">TyCoVarSet
</span><a href="#local-6989586621680969122"><span class="hs-identifier hs-var">main_tv_set</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">([Id] -&gt; [Id]) -&gt; [Id] -&gt; [Id]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1937"></span><span>                   </span><span class="annot"><span class="annottext">[Id] -&gt; [Id]
</span><a href="GHC.Core.TyCo.FVs.html#closeOverKindsList"><span class="hs-identifier hs-var">closeOverKindsList</span></a></span><span> </span><span class="annot"><span class="annottext">([Id] -&gt; [Id]) -&gt; [Id] -&gt; [Id]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1938"></span><span>                   </span><span class="annot"><span class="annottext">(Id -&gt; Bool) -&gt; Expr Id -&gt; [Id]
</span><a href="GHC.Core.FVs.html#exprSomeFreeVarsList"><span class="hs-identifier hs-var">exprSomeFreeVarsList</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Var.html#isTyVar"><span class="hs-identifier hs-var">isTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969105"><span class="hs-identifier hs-var">rhs'</span></a></span><span>
</span><span id="line-1939"></span><span>
</span><span id="line-1940"></span><span>    </span><span class="annot"><a href="#local-6989586621680969126"><span class="hs-identifier hs-var">abstract</span></a></span><span> </span><span id="local-6989586621680969098"><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680969098"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Rec"><span class="hs-identifier hs-type">Rec</span></a></span><span> </span><span id="local-6989586621680969096"><span class="annot"><span class="annottext">[(Id, Expr Id)]
</span><a href="#local-6989586621680969096"><span class="hs-identifier hs-var">prs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1941"></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680969095"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969095"><span class="hs-identifier hs-var">poly_ids</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969094"><span class="annot"><span class="annottext">[Expr Id]
</span><a href="#local-6989586621680969094"><span class="hs-identifier hs-var">poly_apps</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(Id -&gt; SimplM (Id, Expr Id)) -&gt; [Id] -&gt; SimplM ([Id], [Expr Id])
forall (m :: * -&gt; *) a b c.
Applicative m =&gt;
(a -&gt; m (b, c)) -&gt; [a] -&gt; m ([b], [c])
</span><a href="../../base/src/Control.Monad.html#mapAndUnzipM"><span class="hs-identifier hs-var">mapAndUnzipM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Id] -&gt; Id -&gt; SimplM (Id, Expr Id)
</span><a href="#local-6989586621680969110"><span class="hs-identifier hs-var">mk_poly1</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969092"><span class="hs-identifier hs-var">tvs_here</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969091"><span class="hs-identifier hs-var">ids</span></a></span><span>
</span><span id="line-1942"></span><span>            </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680969090"><span class="annot"><span class="annottext">subst' :: Subst
</span><a href="#local-6989586621680969090"><span class="hs-identifier hs-var hs-var">subst'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Subst -&gt; [(Id, Expr Id)] -&gt; Subst
</span><a href="GHC.Core.Subst.html#extendSubstList"><span class="hs-identifier hs-var">GHC.Core.Subst.extendSubstList</span></a></span><span> </span><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680969098"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969091"><span class="hs-identifier hs-var">ids</span></a></span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; [Expr Id] -&gt; [(Id, Expr Id)]
forall a b. [a] -&gt; [b] -&gt; [(a, b)]
</span><a href="../../base/src/GHC.List.html#zip"><span class="hs-operator hs-var">`zip`</span></a></span><span> </span><span class="annot"><span class="annottext">[Expr Id]
</span><a href="#local-6989586621680969094"><span class="hs-identifier hs-var">poly_apps</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1943"></span><span>                  </span><span id="local-6989586621680969088"><span class="annot"><span class="annottext">poly_pairs :: [(Id, Expr Id)]
</span><a href="#local-6989586621680969088"><span class="hs-identifier hs-var hs-var">poly_pairs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Id -&gt; [Id] -&gt; Expr Id -&gt; (Id, Expr Id)
</span><a href="#local-6989586621680969106"><span class="hs-identifier hs-var">mk_poly2</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969087"><span class="hs-identifier hs-var">poly_id</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969092"><span class="hs-identifier hs-var">tvs_here</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969086"><span class="hs-identifier hs-var">rhs'</span></a></span><span>
</span><span id="line-1944"></span><span>                               </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680969087"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969087"><span class="hs-identifier hs-var">poly_id</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969085"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969085"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969095"><span class="hs-identifier hs-var">poly_ids</span></a></span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; [Expr Id] -&gt; [(Id, Expr Id)]
forall a b. [a] -&gt; [b] -&gt; [(a, b)]
</span><a href="../../base/src/GHC.List.html#zip"><span class="hs-operator hs-var">`zip`</span></a></span><span> </span><span class="annot"><span class="annottext">[Expr Id]
</span><a href="#local-6989586621680969084"><span class="hs-identifier hs-var">rhss</span></a></span><span>
</span><span id="line-1945"></span><span>                               </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680969086"><span class="annot"><span class="annottext">rhs' :: Expr Id
</span><a href="#local-6989586621680969086"><span class="hs-identifier hs-var hs-var">rhs'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Subst -&gt; Expr Id -&gt; Expr Id
Subst -&gt; Expr Id -&gt; Expr Id
</span><a href="GHC.Core.Subst.html#substExpr"><span class="hs-identifier hs-var">GHC.Core.Subst.substExpr</span></a></span><span> </span><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680969090"><span class="hs-identifier hs-var">subst'</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969085"><span class="hs-identifier hs-var">rhs</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-1946"></span><span>            </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(Subst, Bind Id) -&gt; SimplM (Subst, Bind Id)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Subst
</span><a href="#local-6989586621680969090"><span class="hs-identifier hs-var">subst'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[(Id, Expr Id)] -&gt; Bind Id
forall b. [(b, Expr b)] -&gt; Bind b
</span><a href="GHC.Core.html#Rec"><span class="hs-identifier hs-var">Rec</span></a></span><span> </span><span class="annot"><span class="annottext">[(Id, Expr Id)]
</span><a href="#local-6989586621680969088"><span class="hs-identifier hs-var">poly_pairs</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1947"></span><span>       </span><span class="hs-keyword">where</span><span>
</span><span id="line-1948"></span><span>         </span><span class="hs-special">(</span><span id="local-6989586621680969091"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969091"><span class="hs-identifier hs-var">ids</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680969084"><span class="annot"><span class="annottext">[Expr Id]
</span><a href="#local-6989586621680969084"><span class="hs-identifier hs-var">rhss</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(Id, Expr Id)] -&gt; ([Id], [Expr Id])
forall a b. [(a, b)] -&gt; ([a], [b])
</span><a href="../../base/src/GHC.List.html#unzip"><span class="hs-identifier hs-var">unzip</span></a></span><span> </span><span class="annot"><span class="annottext">[(Id, Expr Id)]
</span><a href="#local-6989586621680969096"><span class="hs-identifier hs-var">prs</span></a></span><span>
</span><span id="line-1949"></span><span>                </span><span class="hs-comment">-- For a recursive group, it's a bit of a pain to work out the minimal</span><span>
</span><span id="line-1950"></span><span>                </span><span class="hs-comment">-- set of tyvars over which to abstract:</span><span>
</span><span id="line-1951"></span><span>                </span><span class="hs-comment">--      /\ a b c.  let x = ...a... in</span><span>
</span><span id="line-1952"></span><span>                </span><span class="hs-comment">--                 letrec { p = ...x...q...</span><span>
</span><span id="line-1953"></span><span>                </span><span class="hs-comment">--                          q = .....p...b... } in</span><span>
</span><span id="line-1954"></span><span>                </span><span class="hs-comment">--                 ...</span><span>
</span><span id="line-1955"></span><span>                </span><span class="hs-comment">-- Since 'x' is abstracted over 'a', the {p,q} group must be abstracted</span><span>
</span><span id="line-1956"></span><span>                </span><span class="hs-comment">-- over 'a' (because x is replaced by (poly_x a)) as well as 'b'.</span><span>
</span><span id="line-1957"></span><span>                </span><span class="hs-comment">-- Since it's a pain, we just use the whole set, which is always safe</span><span>
</span><span id="line-1958"></span><span>                </span><span class="hs-comment">--</span><span>
</span><span id="line-1959"></span><span>                </span><span class="hs-comment">-- If you ever want to be more selective, remember this bizarre case too:</span><span>
</span><span id="line-1960"></span><span>                </span><span class="hs-comment">--      x::a = x</span><span>
</span><span id="line-1961"></span><span>                </span><span class="hs-comment">-- Here, we must abstract 'x' over 'a'.</span><span>
</span><span id="line-1962"></span><span>         </span><span id="local-6989586621680969092"><span class="annot"><span class="annottext">tvs_here :: [Id]
</span><a href="#local-6989586621680969092"><span class="hs-identifier hs-var hs-var">tvs_here</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; [Id]
</span><a href="GHC.Core.TyCo.FVs.html#scopedSort"><span class="hs-identifier hs-var">scopedSort</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969136"><span class="hs-identifier hs-var">main_tvs</span></a></span><span>
</span><span id="line-1963"></span><span>
</span><span id="line-1964"></span><span>    </span><span class="annot"><a href="#local-6989586621680969110"><span class="hs-identifier hs-type">mk_poly1</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Monad.html#SimplM"><span class="hs-identifier hs-type">SimplM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1965"></span><span>    </span><span id="local-6989586621680969110"><span class="annot"><span class="annottext">mk_poly1 :: [Id] -&gt; Id -&gt; SimplM (Id, Expr Id)
</span><a href="#local-6989586621680969110"><span class="hs-identifier hs-var hs-var">mk_poly1</span></a></span></span><span> </span><span id="local-6989586621680969080"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969080"><span class="hs-identifier hs-var">tvs_here</span></a></span></span><span> </span><span id="local-6989586621680969079"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969079"><span class="hs-identifier hs-var">var</span></a></span></span><span>
</span><span id="line-1966"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680969078"><span class="annot"><span class="annottext">Unique
</span><a href="#local-6989586621680969078"><span class="hs-identifier hs-var">uniq</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">SimplM Unique
forall (m :: * -&gt; *). MonadUnique m =&gt; m Unique
</span><a href="GHC.Types.Unique.Supply.html#getUniqueM"><span class="hs-identifier hs-var">getUniqueM</span></a></span><span>
</span><span id="line-1967"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span>  </span><span id="local-6989586621680969076"><span class="annot"><span class="annottext">poly_name :: Name
</span><a href="#local-6989586621680969076"><span class="hs-identifier hs-var hs-var">poly_name</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name -&gt; Unique -&gt; Name
</span><a href="GHC.Types.Name.html#setNameUnique"><span class="hs-identifier hs-var">setNameUnique</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Name
</span><a href="GHC.Types.Id.html#idName"><span class="hs-identifier hs-var">idName</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969079"><span class="hs-identifier hs-var">var</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Unique
</span><a href="#local-6989586621680969078"><span class="hs-identifier hs-var">uniq</span></a></span><span>      </span><span class="hs-comment">-- Keep same name</span><span>
</span><span id="line-1968"></span><span>                  </span><span id="local-6989586621680969073"><span class="annot"><span class="annottext">poly_ty :: OutType
</span><a href="#local-6989586621680969073"><span class="hs-identifier hs-var hs-var">poly_ty</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; OutType -&gt; OutType
</span><a href="GHC.Core.Type.html#mkInfForAllTys"><span class="hs-identifier hs-var">mkInfForAllTys</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969080"><span class="hs-identifier hs-var">tvs_here</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OutType
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969079"><span class="hs-identifier hs-var">var</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- But new type of course</span><span>
</span><span id="line-1969"></span><span>                  </span><span id="local-6989586621680969070"><span class="annot"><span class="annottext">poly_id :: Id
</span><a href="#local-6989586621680969070"><span class="hs-identifier hs-var hs-var">poly_id</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; [Id] -&gt; Id -&gt; Id
</span><a href="GHC.Types.Id.html#transferPolyIdInfo"><span class="hs-identifier hs-var">transferPolyIdInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969079"><span class="hs-identifier hs-var">var</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969080"><span class="hs-identifier hs-var">tvs_here</span></a></span><span> </span><span class="annot"><span class="annottext">(Id -&gt; Id) -&gt; Id -&gt; Id
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-comment">-- Note [transferPolyIdInfo] in GHC.Types.Id</span><span>
</span><span id="line-1970"></span><span>                              </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Name -&gt; OutType -&gt; OutType -&gt; Id
Name -&gt; OutType -&gt; OutType -&gt; Id
</span><a href="GHC.Types.Id.html#mkLocalId"><span class="hs-identifier hs-var">mkLocalId</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680969076"><span class="hs-identifier hs-var">poly_name</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OutType
</span><a href="GHC.Types.Id.html#idMult"><span class="hs-identifier hs-var">idMult</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969079"><span class="hs-identifier hs-var">var</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969073"><span class="hs-identifier hs-var">poly_ty</span></a></span><span>
</span><span id="line-1971"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(Id, Expr Id) -&gt; SimplM (Id, Expr Id)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969070"><span class="hs-identifier hs-var">poly_id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; [OutType] -&gt; Expr Id
forall b. Expr b -&gt; [OutType] -&gt; Expr b
</span><a href="GHC.Core.html#mkTyApps"><span class="hs-identifier hs-var">mkTyApps</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Expr Id
forall b. Id -&gt; Expr b
</span><a href="GHC.Core.html#Var"><span class="hs-identifier hs-var">Var</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969070"><span class="hs-identifier hs-var">poly_id</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Id] -&gt; [OutType]
</span><a href="GHC.Core.TyCo.Rep.html#mkTyVarTys"><span class="hs-identifier hs-var">mkTyVarTys</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969080"><span class="hs-identifier hs-var">tvs_here</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1972"></span><span>                </span><span class="hs-comment">-- In the olden days, it was crucial to copy the occInfo of the original var,</span><span>
</span><span id="line-1973"></span><span>                </span><span class="hs-comment">-- because we were looking at occurrence-analysed but as yet unsimplified code!</span><span>
</span><span id="line-1974"></span><span>                </span><span class="hs-comment">-- In particular, we mustn't lose the loop breakers.  BUT NOW we are looking</span><span>
</span><span id="line-1975"></span><span>                </span><span class="hs-comment">-- at already simplified code, so it doesn't matter</span><span>
</span><span id="line-1976"></span><span>                </span><span class="hs-comment">--</span><span>
</span><span id="line-1977"></span><span>                </span><span class="hs-comment">-- It's even right to retain single-occurrence or dead-var info:</span><span>
</span><span id="line-1978"></span><span>                </span><span class="hs-comment">-- Suppose we started with  /\a -&gt; let x = E in B</span><span>
</span><span id="line-1979"></span><span>                </span><span class="hs-comment">-- where x occurs once in B. Then we transform to:</span><span>
</span><span id="line-1980"></span><span>                </span><span class="hs-comment">--      let x' = /\a -&gt; E in /\a -&gt; let x* = x' a in B</span><span>
</span><span id="line-1981"></span><span>                </span><span class="hs-comment">-- where x* has an INLINE prag on it.  Now, once x* is inlined,</span><span>
</span><span id="line-1982"></span><span>                </span><span class="hs-comment">-- the occurrences of x' will be just the occurrences originally</span><span>
</span><span id="line-1983"></span><span>                </span><span class="hs-comment">-- pinned on x.</span><span>
</span><span id="line-1984"></span><span>
</span><span id="line-1985"></span><span>    </span><span class="annot"><a href="#local-6989586621680969106"><span class="hs-identifier hs-type">mk_poly2</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1986"></span><span>    </span><span id="local-6989586621680969106"><span class="annot"><span class="annottext">mk_poly2 :: Id -&gt; [Id] -&gt; Expr Id -&gt; (Id, Expr Id)
</span><a href="#local-6989586621680969106"><span class="hs-identifier hs-var hs-var">mk_poly2</span></a></span></span><span> </span><span id="local-6989586621680969065"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969065"><span class="hs-identifier hs-var">poly_id</span></a></span></span><span> </span><span id="local-6989586621680969064"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969064"><span class="hs-identifier hs-var">tvs_here</span></a></span></span><span> </span><span id="local-6989586621680969063"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969063"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-1987"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969065"><span class="hs-identifier hs-var">poly_id</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Unfolding -&gt; Id
</span><a href="GHC.Types.Id.html#setIdUnfolding"><span class="hs-operator hs-var">`setIdUnfolding`</span></a></span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><a href="#local-6989586621680969061"><span class="hs-identifier hs-var">unf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969060"><span class="hs-identifier hs-var">poly_rhs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1988"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-1989"></span><span>        </span><span id="local-6989586621680969060"><span class="annot"><span class="annottext">poly_rhs :: Expr Id
</span><a href="#local-6989586621680969060"><span class="hs-identifier hs-var hs-var">poly_rhs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; Expr Id -&gt; Expr Id
forall b. [b] -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#mkLams"><span class="hs-identifier hs-var">mkLams</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680969064"><span class="hs-identifier hs-var">tvs_here</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969063"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-1990"></span><span>        </span><span id="local-6989586621680969061"><span class="annot"><span class="annottext">unf :: Unfolding
</span><a href="#local-6989586621680969061"><span class="hs-identifier hs-var hs-var">unf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; UnfoldingSource -&gt; Bool -&gt; Bool -&gt; Expr Id -&gt; Unfolding
</span><a href="GHC.Core.Unfold.html#mkUnfolding"><span class="hs-identifier hs-var">mkUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969138"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">UnfoldingSource
</span><a href="GHC.Core.html#InlineRhs"><span class="hs-identifier hs-var">InlineRhs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969123"><span class="hs-identifier hs-var">is_top_lvl</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969060"><span class="hs-identifier hs-var">poly_rhs</span></a></span><span>
</span><span id="line-1991"></span><span>
</span><span id="line-1992"></span><span>        </span><span class="hs-comment">-- We want the unfolding.  Consider</span><span>
</span><span id="line-1993"></span><span>        </span><span class="hs-comment">--      let</span><span>
</span><span id="line-1994"></span><span>        </span><span class="hs-comment">--            x = /\a. let y = ... in Just y</span><span>
</span><span id="line-1995"></span><span>        </span><span class="hs-comment">--      in body</span><span>
</span><span id="line-1996"></span><span>        </span><span class="hs-comment">-- Then we float the y-binding out (via abstractFloats and addPolyBind)</span><span>
</span><span id="line-1997"></span><span>        </span><span class="hs-comment">-- but 'x' may well then be inlined in 'body' in which case we'd like the</span><span>
</span><span id="line-1998"></span><span>        </span><span class="hs-comment">-- opportunity to inline 'y' too.</span><span>
</span><span id="line-1999"></span><span>
</span><span id="line-2000"></span><span class="hs-comment">{-
Note [Abstract over coercions]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If a coercion variable (g :: a ~ Int) is free in the RHS, then so is the
type variable a.  Rather than sort this mess out, we simply bale out and abstract
wrt all the type variables if any of them are coercion variables.


Historical note: if you use let-bindings instead of a substitution, beware of this:

                -- Suppose we start with:
                --
                --      x = /\ a -&gt; let g = G in E
                --
                -- Then we'll float to get
                --
                --      x = let poly_g = /\ a -&gt; G
                --          in /\ a -&gt; let g = poly_g a in E
                --
                -- But now the occurrence analyser will see just one occurrence
                -- of poly_g, not inside a lambda, so the simplifier will
                -- PreInlineUnconditionally poly_g back into g!  Badk to square 1!
                -- (I used to think that the &quot;don't inline lone occurrences&quot; stuff
                --  would stop this happening, but since it's the *only* occurrence,
                --  PreInlineUnconditionally kicks in first!)
                --
                -- Solution: put an INLINE note on g's RHS, so that poly_g seems
                --           to appear many times.  (NB: mkInlineMe eliminates
                --           such notes on trivial RHSs, so do it manually.)

************************************************************************
*                                                                      *
                prepareAlts
*                                                                      *
************************************************************************

prepareAlts tries these things:

1.  filterAlts: eliminate alternatives that cannot match, including
    the DEFAULT alternative.  Here &quot;cannot match&quot; includes knowledge
    from GADTs

2.  refineDefaultAlt: if the DEFAULT alternative can match only one
    possible constructor, then make that constructor explicit.
    e.g.
        case e of x { DEFAULT -&gt; rhs }
     ===&gt;
        case e of x { (a,b) -&gt; rhs }
    where the type is a single constructor type.  This gives better code
    when rhs also scrutinises x or e.
    See CoreUtils Note [Refine DEFAULT case alternatives]

3. combineIdenticalAlts: combine identical alternatives into a DEFAULT.
   See CoreUtils Note [Combine identical alternatives], which also
   says why we do this on InAlts not on OutAlts

4. Returns a list of the constructors that cannot holds in the
   DEFAULT alternative (if there is one)

It's a good idea to do this stuff before simplifying the alternatives, to
avoid simplifying alternatives we know can't happen, and to come up with
the list of constructors that are handled, to put into the IdInfo of the
case binder, for use when simplifying the alternatives.

Eliminating the default alternative in (1) isn't so obvious, but it can
happen:

data Colour = Red | Green | Blue

f x = case x of
        Red -&gt; ..
        Green -&gt; ..
        DEFAULT -&gt; h x

h y = case y of
        Blue -&gt; ..
        DEFAULT -&gt; [ case y of ... ]

If we inline h into f, the default case of the inlined h can't happen.
If we don't notice this, we may end up filtering out *all* the cases
of the inner case y, which give us nowhere to go!
-}</span><span>
</span><span id="line-2082"></span><span>
</span><span id="line-2083"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#prepareAlts"><span class="hs-identifier hs-type">prepareAlts</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#OutId"><span class="hs-identifier hs-type">OutId</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#InAlt"><span class="hs-identifier hs-type">InAlt</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Monad.html#SimplM"><span class="hs-identifier hs-type">SimplM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#AltCon"><span class="hs-identifier hs-type">AltCon</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#InAlt"><span class="hs-identifier hs-type">InAlt</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-2084"></span><span class="hs-comment">-- The returned alternatives can be empty, none are possible</span><span>
</span><span id="line-2085"></span><span id="prepareAlts"><span class="annot"><span class="annottext">prepareAlts :: Expr Id -&gt; Id -&gt; [InAlt] -&gt; SimplM ([AltCon], [InAlt])
</span><a href="GHC.Core.Opt.Simplify.Utils.html#prepareAlts"><span class="hs-identifier hs-var hs-var">prepareAlts</span></a></span></span><span> </span><span id="local-6989586621680969057"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969057"><span class="hs-identifier hs-var">scrut</span></a></span></span><span> </span><span id="local-6989586621680969056"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969056"><span class="hs-identifier hs-var">case_bndr'</span></a></span></span><span> </span><span id="local-6989586621680969055"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969055"><span class="hs-identifier hs-var">alts</span></a></span></span><span>
</span><span id="line-2086"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680969054"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621680969054"><span class="hs-identifier hs-var">tc</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969053"><span class="annot"><span class="annottext">[OutType]
</span><a href="#local-6989586621680969053"><span class="hs-identifier hs-var">tys</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; OutType -&gt; Maybe (TyCon, [OutType])
OutType -&gt; Maybe (TyCon, [OutType])
</span><a href="GHC.Core.Type.html#splitTyConApp_maybe"><span class="hs-identifier hs-var">splitTyConApp_maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OutType
</span><a href="GHC.Types.Var.html#varType"><span class="hs-identifier hs-var hs-var">varType</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969056"><span class="hs-identifier hs-var">case_bndr'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2087"></span><span>           </span><span class="hs-comment">-- Case binder is needed just for its type. Note that as an</span><span>
</span><span id="line-2088"></span><span>           </span><span class="hs-comment">--   OutId, it has maximum information; this is important.</span><span>
</span><span id="line-2089"></span><span>           </span><span class="hs-comment">--   Test simpl013 is an example</span><span>
</span><span id="line-2090"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680969050"><span class="annot"><span class="annottext">[Unique]
</span><a href="#local-6989586621680969050"><span class="hs-identifier hs-var">us</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">SimplM [Unique]
forall (m :: * -&gt; *). MonadUnique m =&gt; m [Unique]
</span><a href="GHC.Types.Unique.Supply.html#getUniquesM"><span class="hs-identifier hs-var">getUniquesM</span></a></span><span>
</span><span id="line-2091"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680969048"><span class="annot"><span class="annottext">[AltCon]
</span><a href="#local-6989586621680969048"><span class="hs-identifier hs-var">idcs1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969047"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969047"><span class="hs-identifier hs-var">alts1</span></a></span></span><span class="hs-special">)</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [OutType] -&gt; [AltCon] -&gt; [InAlt] -&gt; ([AltCon], [InAlt])
forall a.
TyCon
-&gt; [OutType]
-&gt; [AltCon]
-&gt; [(AltCon, [Id], a)]
-&gt; ([AltCon], [(AltCon, [Id], a)])
</span><a href="GHC.Core.Utils.html#filterAlts"><span class="hs-identifier hs-var">filterAlts</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621680969054"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[OutType]
</span><a href="#local-6989586621680969053"><span class="hs-identifier hs-var">tys</span></a></span><span> </span><span class="annot"><span class="annottext">[AltCon]
</span><a href="#local-6989586621680969045"><span class="hs-identifier hs-var">imposs_cons</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969055"><span class="hs-identifier hs-var">alts</span></a></span><span>
</span><span id="line-2092"></span><span>             </span><span class="hs-special">(</span><span id="local-6989586621680969044"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969044"><span class="hs-identifier hs-var">yes2</span></a></span></span><span class="hs-special">,</span><span>  </span><span id="local-6989586621680969043"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969043"><span class="hs-identifier hs-var">alts2</span></a></span></span><span class="hs-special">)</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Unique]
-&gt; OutType
-&gt; TyCon
-&gt; [OutType]
-&gt; [AltCon]
-&gt; [InAlt]
-&gt; (Bool, [InAlt])
</span><a href="GHC.Core.Utils.html#refineDefaultAlt"><span class="hs-identifier hs-var">refineDefaultAlt</span></a></span><span> </span><span class="annot"><span class="annottext">[Unique]
</span><a href="#local-6989586621680969050"><span class="hs-identifier hs-var">us</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OutType
</span><a href="GHC.Types.Id.html#idMult"><span class="hs-identifier hs-var">idMult</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969056"><span class="hs-identifier hs-var">case_bndr'</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621680969054"><span class="hs-identifier hs-var">tc</span></a></span><span> </span><span class="annot"><span class="annottext">[OutType]
</span><a href="#local-6989586621680969053"><span class="hs-identifier hs-var">tys</span></a></span><span> </span><span class="annot"><span class="annottext">[AltCon]
</span><a href="#local-6989586621680969048"><span class="hs-identifier hs-var">idcs1</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969047"><span class="hs-identifier hs-var">alts1</span></a></span><span>
</span><span id="line-2093"></span><span>               </span><span class="hs-comment">-- the multiplicity on case_bndr's is the multiplicity of the</span><span>
</span><span id="line-2094"></span><span>               </span><span class="hs-comment">-- case expression The newly introduced patterns in</span><span>
</span><span id="line-2095"></span><span>               </span><span class="hs-comment">-- refineDefaultAlt must be scaled by this multiplicity</span><span>
</span><span id="line-2096"></span><span>             </span><span class="hs-special">(</span><span id="local-6989586621680969041"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969041"><span class="hs-identifier hs-var">yes3</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969040"><span class="annot"><span class="annottext">[AltCon]
</span><a href="#local-6989586621680969040"><span class="hs-identifier hs-var">idcs3</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969039"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969039"><span class="hs-identifier hs-var">alts3</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[AltCon] -&gt; [InAlt] -&gt; (Bool, [AltCon], [InAlt])
</span><a href="GHC.Core.Utils.html#combineIdenticalAlts"><span class="hs-identifier hs-var">combineIdenticalAlts</span></a></span><span> </span><span class="annot"><span class="annottext">[AltCon]
</span><a href="#local-6989586621680969048"><span class="hs-identifier hs-var">idcs1</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969043"><span class="hs-identifier hs-var">alts2</span></a></span><span>
</span><span id="line-2097"></span><span>             </span><span class="hs-comment">-- &quot;idcs&quot; stands for &quot;impossible default data constructors&quot;</span><span>
</span><span id="line-2098"></span><span>             </span><span class="hs-comment">-- i.e. the constructors that can't match the default case</span><span>
</span><span id="line-2099"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SimplM () -&gt; SimplM ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969044"><span class="hs-identifier hs-var">yes2</span></a></span><span> </span><span class="annot"><span class="annottext">(SimplM () -&gt; SimplM ()) -&gt; SimplM () -&gt; SimplM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Tick -&gt; SimplM ()
</span><a href="GHC.Core.Opt.Simplify.Monad.html#tick"><span class="hs-identifier hs-var">tick</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Tick
</span><a href="GHC.Core.Opt.Monad.html#FillInCaseDefault"><span class="hs-identifier hs-var">FillInCaseDefault</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969056"><span class="hs-identifier hs-var">case_bndr'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2100"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SimplM () -&gt; SimplM ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680969041"><span class="hs-identifier hs-var">yes3</span></a></span><span> </span><span class="annot"><span class="annottext">(SimplM () -&gt; SimplM ()) -&gt; SimplM () -&gt; SimplM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Tick -&gt; SimplM ()
</span><a href="GHC.Core.Opt.Simplify.Monad.html#tick"><span class="hs-identifier hs-var">tick</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Tick
</span><a href="GHC.Core.Opt.Monad.html#AltMerge"><span class="hs-identifier hs-var">AltMerge</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969056"><span class="hs-identifier hs-var">case_bndr'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2101"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">([AltCon], [InAlt]) -&gt; SimplM ([AltCon], [InAlt])
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[AltCon]
</span><a href="#local-6989586621680969040"><span class="hs-identifier hs-var">idcs3</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969039"><span class="hs-identifier hs-var">alts3</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-2102"></span><span>
</span><span id="line-2103"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>  </span><span class="hs-comment">-- Not a data type, so nothing interesting happens</span><span>
</span><span id="line-2104"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">([AltCon], [InAlt]) -&gt; SimplM ([AltCon], [InAlt])
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969055"><span class="hs-identifier hs-var">alts</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2105"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-2106"></span><span>    </span><span id="local-6989586621680969045"><span class="annot"><span class="annottext">imposs_cons :: [AltCon]
</span><a href="#local-6989586621680969045"><span class="hs-identifier hs-var hs-var">imposs_cons</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969057"><span class="hs-identifier hs-var">scrut</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-2107"></span><span>                    </span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680969035"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969035"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Unfolding -&gt; [AltCon]
</span><a href="GHC.Core.html#otherCons"><span class="hs-identifier hs-var">otherCons</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Unfolding
</span><a href="GHC.Types.Id.html#idUnfolding"><span class="hs-identifier hs-var">idUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969035"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2108"></span><span>                    </span><span class="annot"><span class="annottext">Expr Id
</span><span class="hs-identifier">_</span></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-2109"></span><span>
</span><span id="line-2110"></span><span>
</span><span id="line-2111"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
                mkCase
*                                                                      *
************************************************************************

mkCase tries these things

* Note [Nerge nested cases]
* Note [Eliminate identity case]
* Note [Scrutinee constant folding]

Note [Merge Nested Cases]
~~~~~~~~~~~~~~~~~~~~~~~~~
       case e of b {             ==&gt;   case e of b {
         p1 -&gt; rhs1                      p1 -&gt; rhs1
         ...                             ...
         pm -&gt; rhsm                      pm -&gt; rhsm
         _  -&gt; case b of b' {            pn -&gt; let b'=b in rhsn
                     pn -&gt; rhsn          ...
                     ...                 po -&gt; let b'=b in rhso
                     po -&gt; rhso          _  -&gt; let b'=b in rhsd
                     _  -&gt; rhsd
       }

which merges two cases in one case when -- the default alternative of
the outer case scrutises the same variable as the outer case. This
transformation is called Case Merging.  It avoids that the same
variable is scrutinised multiple times.

Note [Eliminate Identity Case]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        case e of               ===&gt; e
                True  -&gt; True;
                False -&gt; False

and similar friends.

Note [Scrutinee Constant Folding]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     case x op# k# of _ {  ===&gt; case x of _ {
        a1# -&gt; e1                  (a1# inv_op# k#) -&gt; e1
        a2# -&gt; e2                  (a2# inv_op# k#) -&gt; e2
        ...                        ...
        DEFAULT -&gt; ed              DEFAULT -&gt; ed

     where (x op# k#) inv_op# k# == x

And similarly for commuted arguments and for some unary operations.

The purpose of this transformation is not only to avoid an arithmetic
operation at runtime but to allow other transformations to apply in cascade.

Example with the &quot;Merge Nested Cases&quot; optimization (from #12877):

      main = case t of t0
         0##     -&gt; ...
         DEFAULT -&gt; case t0 `minusWord#` 1## of t1
            0##     -&gt; ...
            DEFAULT -&gt; case t1 `minusWord#` 1## of t2
               0##     -&gt; ...
               DEFAULT -&gt; case t2 `minusWord#` 1## of _
                  0##     -&gt; ...
                  DEFAULT -&gt; ...

  becomes:

      main = case t of _
      0##     -&gt; ...
      1##     -&gt; ...
      2##     -&gt; ...
      3##     -&gt; ...
      DEFAULT -&gt; ...

There are some wrinkles

* Do not apply caseRules if there is just a single DEFAULT alternative
     case e +# 3# of b { DEFAULT -&gt; rhs }
  If we applied the transformation here we would (stupidly) get
     case a of b' { DEFAULT -&gt; let b = e +# 3# in rhs }
  and now the process may repeat, because that let will really
  be a case.

* The type of the scrutinee might change.  E.g.
        case tagToEnum (x :: Int#) of (b::Bool)
          False -&gt; e1
          True -&gt; e2
  ==&gt;
        case x of (b'::Int#)
          DEFAULT -&gt; e1
          1#      -&gt; e2

* The case binder may be used in the right hand sides, so we need
  to make a local binding for it, if it is alive.  e.g.
         case e +# 10# of b
           DEFAULT -&gt; blah...b...
           44#     -&gt; blah2...b...
  ===&gt;
         case e of b'
           DEFAULT -&gt; let b = b' +# 10# in blah...b...
           34#     -&gt; let b = 44# in blah2...b...

  Note that in the non-DEFAULT cases we know what to bind 'b' to,
  whereas in the DEFAULT case we must reconstruct the original value.
  But NB: we use b'; we do not duplicate 'e'.

* In dataToTag we might need to make up some fake binders;
  see Note [caseRules for dataToTag] in GHC.Core.Opt.ConstantFold
-}</span><span>
</span><span id="line-2221"></span><span>
</span><span id="line-2222"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase"><span class="hs-identifier hs-type">mkCase</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase1"><span class="hs-identifier hs-type">mkCase1</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase2"><span class="hs-identifier hs-type">mkCase2</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase3"><span class="hs-identifier hs-type">mkCase3</span></a></span><span>
</span><span id="line-2223"></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span>
</span><span id="line-2224"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#OutId"><span class="hs-identifier hs-type">OutId</span></a></span><span>
</span><span id="line-2225"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#OutType"><span class="hs-identifier hs-type">OutType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#OutAlt"><span class="hs-identifier hs-type">OutAlt</span></a></span><span class="hs-special">]</span><span>               </span><span class="hs-comment">-- Alternatives in standard (increasing) order</span><span>
</span><span id="line-2226"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Monad.html#SimplM"><span class="hs-identifier hs-type">SimplM</span></a></span><span> </span><span class="annot"><a href="GHC.Core.html#OutExpr"><span class="hs-identifier hs-type">OutExpr</span></a></span><span>
</span><span id="line-2227"></span><span>
</span><span id="line-2228"></span><span class="hs-comment">--------------------------------------------------</span><span>
</span><span id="line-2229"></span><span class="hs-comment">--      1. Merge Nested Cases</span><span>
</span><span id="line-2230"></span><span class="hs-comment">--------------------------------------------------</span><span>
</span><span id="line-2231"></span><span>
</span><span id="line-2232"></span><span id="mkCase"><span class="annot"><span class="annottext">mkCase :: DynFlags -&gt; Expr Id -&gt; Id -&gt; OutType -&gt; [InAlt] -&gt; SimplM (Expr Id)
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase"><span class="hs-identifier hs-var hs-var">mkCase</span></a></span></span><span> </span><span id="local-6989586621680969029"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969029"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680969028"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969028"><span class="hs-identifier hs-var">scrut</span></a></span></span><span> </span><span id="local-6989586621680969027"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969027"><span class="hs-identifier hs-var">outer_bndr</span></a></span></span><span> </span><span id="local-6989586621680969026"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969026"><span class="hs-identifier hs-var">alts_ty</span></a></span></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">AltCon
</span><a href="GHC.Core.html#DEFAULT"><span class="hs-identifier hs-var">DEFAULT</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Id]
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969024"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969024"><span class="hs-identifier hs-var">deflt_rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680969023"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969023"><span class="hs-identifier hs-var">outer_alts</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-2233"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">GeneralFlag -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#gopt"><span class="hs-identifier hs-var">gopt</span></a></span><span> </span><span class="annot"><span class="annottext">GeneralFlag
</span><a href="GHC.Driver.Flags.html#Opt_CaseMerge"><span class="hs-identifier hs-var">Opt_CaseMerge</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969029"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-2234"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680969021"><span class="annot"><span class="annottext">[Tickish Id]
</span><a href="#local-6989586621680969021"><span class="hs-identifier hs-var">ticks</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#Case"><span class="hs-identifier hs-type">Case</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680969020"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969020"><span class="hs-identifier hs-var">inner_scrut_var</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680969019"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969019"><span class="hs-identifier hs-var">inner_bndr</span></a></span></span><span> </span><span class="annot"><span class="annottext">OutType
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680969018"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969018"><span class="hs-identifier hs-var">inner_alts</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-2235"></span><span>       </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(Tickish Id -&gt; Bool) -&gt; Expr Id -&gt; ([Tickish Id], Expr Id)
forall b. (Tickish Id -&gt; Bool) -&gt; Expr b -&gt; ([Tickish Id], Expr b)
</span><a href="GHC.Core.Utils.html#stripTicksTop"><span class="hs-identifier hs-var">stripTicksTop</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id -&gt; Bool
forall id. Tickish id -&gt; Bool
</span><a href="GHC.Core.html#tickishFloatable"><span class="hs-identifier hs-var">tickishFloatable</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969024"><span class="hs-identifier hs-var">deflt_rhs</span></a></span><span>
</span><span id="line-2236"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969020"><span class="hs-identifier hs-var">inner_scrut_var</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Id -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969027"><span class="hs-identifier hs-var">outer_bndr</span></a></span><span>
</span><span id="line-2237"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>  </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">Tick -&gt; SimplM ()
</span><a href="GHC.Core.Opt.Simplify.Monad.html#tick"><span class="hs-identifier hs-var">tick</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Tick
</span><a href="GHC.Core.Opt.Monad.html#CaseMerge"><span class="hs-identifier hs-var">CaseMerge</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969027"><span class="hs-identifier hs-var">outer_bndr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2238"></span><span>
</span><span id="line-2239"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680969012"><span class="annot"><span class="annottext">wrap_alt :: (a, t Id, Expr Id) -&gt; (a, t Id, Expr Id)
</span><a href="#local-6989586621680969012"><span class="hs-identifier hs-var hs-var">wrap_alt</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680969011"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680969011"><span class="hs-identifier hs-var">con</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969010"><span class="annot"><span class="annottext">t Id
</span><a href="#local-6989586621680969010"><span class="hs-identifier hs-var">args</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680969009"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969009"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">outer_bndr</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">notElem</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">args</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-2240"></span><span>                                          </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680969011"><span class="hs-identifier hs-var">con</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">t Id
</span><a href="#local-6989586621680969010"><span class="hs-identifier hs-var">args</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Expr Id
</span><a href="#local-6989586621680969007"><span class="hs-identifier hs-var">wrap_rhs</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969009"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2241"></span><span>                </span><span class="hs-comment">-- Simplifier's no-shadowing invariant should ensure</span><span>
</span><span id="line-2242"></span><span>                </span><span class="hs-comment">-- that outer_bndr is not shadowed by the inner patterns</span><span>
</span><span id="line-2243"></span><span>              </span><span id="local-6989586621680969007"><span class="annot"><span class="annottext">wrap_rhs :: Expr Id -&gt; Expr Id
</span><a href="#local-6989586621680969007"><span class="hs-identifier hs-var hs-var">wrap_rhs</span></a></span></span><span> </span><span id="local-6989586621680969006"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969006"><span class="hs-identifier hs-var">rhs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bind Id -&gt; Expr Id -&gt; Expr Id
forall b. Bind b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#Let"><span class="hs-identifier hs-var">Let</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Expr Id -&gt; Bind Id
forall b. b -&gt; Expr b -&gt; Bind b
</span><a href="GHC.Core.html#NonRec"><span class="hs-identifier hs-var">NonRec</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969019"><span class="hs-identifier hs-var">inner_bndr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Expr Id
forall b. Id -&gt; Expr b
</span><a href="GHC.Core.html#Var"><span class="hs-identifier hs-var">Var</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969027"><span class="hs-identifier hs-var">outer_bndr</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969006"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-2244"></span><span>                </span><span class="hs-comment">-- The let is OK even for unboxed binders,</span><span>
</span><span id="line-2245"></span><span>
</span><span id="line-2246"></span><span>              </span><span id="local-6989586621680969004"><span class="annot"><span class="annottext">wrapped_alts :: [InAlt]
</span><a href="#local-6989586621680969004"><span class="hs-identifier hs-var hs-var">wrapped_alts</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Id.html#isDeadBinder"><span class="hs-identifier hs-var">isDeadBinder</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969019"><span class="hs-identifier hs-var">inner_bndr</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969018"><span class="hs-identifier hs-var">inner_alts</span></a></span><span>
</span><span id="line-2247"></span><span>                           </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>               </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(InAlt -&gt; InAlt) -&gt; [InAlt] -&gt; [InAlt]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">InAlt -&gt; InAlt
forall {t :: * -&gt; *} {a}.
Foldable t =&gt;
(a, t Id, Expr Id) -&gt; (a, t Id, Expr Id)
</span><a href="#local-6989586621680969012"><span class="hs-identifier hs-var">wrap_alt</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969018"><span class="hs-identifier hs-var">inner_alts</span></a></span><span>
</span><span id="line-2248"></span><span>
</span><span id="line-2249"></span><span>              </span><span id="local-6989586621680969002"><span class="annot"><span class="annottext">merged_alts :: [InAlt]
</span><a href="#local-6989586621680969002"><span class="hs-identifier hs-var hs-var">merged_alts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[InAlt] -&gt; [InAlt] -&gt; [InAlt]
forall a b.
[(AltCon, a, b)] -&gt; [(AltCon, a, b)] -&gt; [(AltCon, a, b)]
</span><a href="GHC.Core.Utils.html#mergeAlts"><span class="hs-identifier hs-var">mergeAlts</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969023"><span class="hs-identifier hs-var">outer_alts</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969004"><span class="hs-identifier hs-var">wrapped_alts</span></a></span><span>
</span><span id="line-2250"></span><span>                </span><span class="hs-comment">-- NB: mergeAlts gives priority to the left</span><span>
</span><span id="line-2251"></span><span>                </span><span class="hs-comment">--      case x of</span><span>
</span><span id="line-2252"></span><span>                </span><span class="hs-comment">--        A -&gt; e1</span><span>
</span><span id="line-2253"></span><span>                </span><span class="hs-comment">--        DEFAULT -&gt; case x of</span><span>
</span><span id="line-2254"></span><span>                </span><span class="hs-comment">--                      A -&gt; e2</span><span>
</span><span id="line-2255"></span><span>                </span><span class="hs-comment">--                      B -&gt; e3</span><span>
</span><span id="line-2256"></span><span>                </span><span class="hs-comment">-- When we merge, we must ensure that e1 takes</span><span>
</span><span id="line-2257"></span><span>                </span><span class="hs-comment">-- precedence over e2 as the value for A!</span><span>
</span><span id="line-2258"></span><span>
</span><span id="line-2259"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">(Expr Id -&gt; Expr Id) -&gt; SimplM (Expr Id) -&gt; SimplM (Expr Id)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Tickish Id] -&gt; Expr Id -&gt; Expr Id
</span><a href="GHC.Core.Utils.html#mkTicks"><span class="hs-identifier hs-var">mkTicks</span></a></span><span> </span><span class="annot"><span class="annottext">[Tickish Id]
</span><a href="#local-6989586621680969021"><span class="hs-identifier hs-var">ticks</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(SimplM (Expr Id) -&gt; SimplM (Expr Id))
-&gt; SimplM (Expr Id) -&gt; SimplM (Expr Id)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-2260"></span><span>          </span><span class="annot"><span class="annottext">DynFlags -&gt; Expr Id -&gt; Id -&gt; OutType -&gt; [InAlt] -&gt; SimplM (Expr Id)
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase1"><span class="hs-identifier hs-var">mkCase1</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680969029"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680969028"><span class="hs-identifier hs-var">scrut</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680969027"><span class="hs-identifier hs-var">outer_bndr</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680969026"><span class="hs-identifier hs-var">alts_ty</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680969002"><span class="hs-identifier hs-var">merged_alts</span></a></span><span>
</span><span id="line-2261"></span><span>        </span><span class="hs-special">}</span><span>
</span><span id="line-2262"></span><span>        </span><span class="hs-comment">-- Warning: don't call mkCase recursively!</span><span>
</span><span id="line-2263"></span><span>        </span><span class="hs-comment">-- Firstly, there's no point, because inner alts have already had</span><span>
</span><span id="line-2264"></span><span>        </span><span class="hs-comment">-- mkCase applied to them, so they won't have a case in their default</span><span>
</span><span id="line-2265"></span><span>        </span><span class="hs-comment">-- Secondly, if you do, you get an infinite loop, because the bindCaseBndr</span><span>
</span><span id="line-2266"></span><span>        </span><span class="hs-comment">-- in munge_rhs may put a case into the DEFAULT branch!</span><span>
</span><span id="line-2267"></span><span>
</span><span id="line-2268"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase"><span class="hs-identifier hs-var">mkCase</span></a></span><span> </span><span id="local-6989586621680968999"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680968999"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680968998"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968998"><span class="hs-identifier hs-var">scrut</span></a></span></span><span> </span><span id="local-6989586621680968997"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968997"><span class="hs-identifier hs-var">bndr</span></a></span></span><span> </span><span id="local-6989586621680968996"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680968996"><span class="hs-identifier hs-var">alts_ty</span></a></span></span><span> </span><span id="local-6989586621680968995"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968995"><span class="hs-identifier hs-var">alts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Expr Id -&gt; Id -&gt; OutType -&gt; [InAlt] -&gt; SimplM (Expr Id)
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase1"><span class="hs-identifier hs-var">mkCase1</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680968999"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968998"><span class="hs-identifier hs-var">scrut</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968997"><span class="hs-identifier hs-var">bndr</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680968996"><span class="hs-identifier hs-var">alts_ty</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968995"><span class="hs-identifier hs-var">alts</span></a></span><span>
</span><span id="line-2269"></span><span>
</span><span id="line-2270"></span><span class="hs-comment">--------------------------------------------------</span><span>
</span><span id="line-2271"></span><span class="hs-comment">--      2. Eliminate Identity Case</span><span>
</span><span id="line-2272"></span><span class="hs-comment">--------------------------------------------------</span><span>
</span><span id="line-2273"></span><span>
</span><span id="line-2274"></span><span id="mkCase1"><span class="annot"><span class="annottext">mkCase1 :: DynFlags -&gt; Expr Id -&gt; Id -&gt; OutType -&gt; [InAlt] -&gt; SimplM (Expr Id)
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase1"><span class="hs-identifier hs-var hs-var">mkCase1</span></a></span></span><span> </span><span id="local-6989586621680968994"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680968994"><span class="hs-identifier hs-var">_dflags</span></a></span></span><span> </span><span id="local-6989586621680968993"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968993"><span class="hs-identifier hs-var">scrut</span></a></span></span><span> </span><span id="local-6989586621680968992"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968992"><span class="hs-identifier hs-var">case_bndr</span></a></span></span><span> </span><span class="annot"><span class="annottext">OutType
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621680968991"><span class="annot"><span class="annottext">alts :: [InAlt]
</span><a href="#local-6989586621680968991"><span class="hs-identifier hs-var">alts</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">AltCon
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">[Id]
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span id="local-6989586621680968990"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968990"><span class="hs-identifier hs-var">rhs1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>      </span><span class="hs-comment">-- Identity case</span><span>
</span><span id="line-2275"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">(InAlt -&gt; Bool) -&gt; [InAlt] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#all"><span class="hs-identifier hs-var">all</span></a></span><span> </span><span class="annot"><span class="annottext">InAlt -&gt; Bool
forall {b}. (AltCon, [Id], Expr b) -&gt; Bool
</span><a href="#local-6989586621680968988"><span class="hs-identifier hs-var">identity_alt</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968991"><span class="hs-identifier hs-var">alts</span></a></span><span>
</span><span id="line-2276"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">Tick -&gt; SimplM ()
</span><a href="GHC.Core.Opt.Simplify.Monad.html#tick"><span class="hs-identifier hs-var">tick</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Tick
</span><a href="GHC.Core.Opt.Monad.html#CaseIdentity"><span class="hs-identifier hs-var">CaseIdentity</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968992"><span class="hs-identifier hs-var">case_bndr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2277"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; SimplM (Expr Id)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Tickish Id] -&gt; Expr Id -&gt; Expr Id
</span><a href="GHC.Core.Utils.html#mkTicks"><span class="hs-identifier hs-var">mkTicks</span></a></span><span> </span><span class="annot"><span class="annottext">[Tickish Id]
</span><a href="#local-6989586621680968986"><span class="hs-identifier hs-var">ticks</span></a></span><span> </span><span class="annot"><span class="annottext">(Expr Id -&gt; Expr Id) -&gt; Expr Id -&gt; Expr Id
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; Expr Id -&gt; Expr Id
forall {b} {b}. Expr b -&gt; Expr b -&gt; Expr b
</span><a href="#local-6989586621680968985"><span class="hs-identifier hs-var">re_cast</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968993"><span class="hs-identifier hs-var">scrut</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968990"><span class="hs-identifier hs-var">rhs1</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-2278"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-2279"></span><span>    </span><span id="local-6989586621680968986"><span class="annot"><span class="annottext">ticks :: [Tickish Id]
</span><a href="#local-6989586621680968986"><span class="hs-identifier hs-var hs-var">ticks</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(InAlt -&gt; [Tickish Id]) -&gt; [InAlt] -&gt; [Tickish Id]
forall (t :: * -&gt; *) a b. Foldable t =&gt; (a -&gt; [b]) -&gt; t a -&gt; [b]
</span><a href="../../base/src/Data.Foldable.html#concatMap"><span class="hs-identifier hs-var">concatMap</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Tickish Id -&gt; Bool) -&gt; Expr Id -&gt; [Tickish Id]
forall b. (Tickish Id -&gt; Bool) -&gt; Expr b -&gt; [Tickish Id]
</span><a href="GHC.Core.Utils.html#stripTicksT"><span class="hs-identifier hs-var">stripTicksT</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id -&gt; Bool
forall id. Tickish id -&gt; Bool
</span><a href="GHC.Core.html#tickishFloatable"><span class="hs-identifier hs-var">tickishFloatable</span></a></span><span> </span><span class="annot"><span class="annottext">(Expr Id -&gt; [Tickish Id])
-&gt; (InAlt -&gt; Expr Id) -&gt; InAlt -&gt; [Tickish Id]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">InAlt -&gt; Expr Id
forall a b c. (a, b, c) -&gt; c
</span><a href="GHC.Utils.Misc.html#thdOf3"><span class="hs-identifier hs-var">thdOf3</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[InAlt] -&gt; [InAlt]
forall a. [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#tail"><span class="hs-identifier hs-var">tail</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968991"><span class="hs-identifier hs-var">alts</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2280"></span><span>    </span><span id="local-6989586621680968988"><span class="annot"><span class="annottext">identity_alt :: (AltCon, [Id], Expr b) -&gt; Bool
</span><a href="#local-6989586621680968988"><span class="hs-identifier hs-var hs-var">identity_alt</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680968978"><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680968978"><span class="hs-identifier hs-var">con</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680968977"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968977"><span class="hs-identifier hs-var">args</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680968976"><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680968976"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr b -&gt; AltCon -&gt; [Id] -&gt; Bool
forall {b}. Expr b -&gt; AltCon -&gt; [Id] -&gt; Bool
</span><a href="#local-6989586621680968975"><span class="hs-identifier hs-var">check_eq</span></a></span><span> </span><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680968976"><span class="hs-identifier hs-var">rhs</span></a></span><span> </span><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680968978"><span class="hs-identifier hs-var">con</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968977"><span class="hs-identifier hs-var">args</span></a></span><span>
</span><span id="line-2281"></span><span>
</span><span id="line-2282"></span><span>    </span><span id="local-6989586621680968975"><span class="annot"><span class="annottext">check_eq :: Expr b -&gt; AltCon -&gt; [Id] -&gt; Bool
</span><a href="#local-6989586621680968975"><span class="hs-identifier hs-var hs-var">check_eq</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-type">Cast</span></a></span><span> </span><span id="local-6989586621680968967"><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680968967"><span class="hs-identifier hs-var">rhs</span></a></span></span><span> </span><span id="local-6989586621680968966"><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680968966"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680968965"><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680968965"><span class="hs-identifier hs-var">con</span></a></span></span><span> </span><span id="local-6989586621680968964"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968964"><span class="hs-identifier hs-var">args</span></a></span></span><span>        </span><span class="hs-comment">-- See Note [RHS casts]</span><span>
</span><span id="line-2283"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Id -&gt; Bool) -&gt; [Id] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#any"><span class="hs-identifier hs-var">any</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; TyCoVarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#elemVarSet"><span class="hs-operator hs-var">`elemVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion -&gt; TyCoVarSet
</span><a href="GHC.Core.TyCo.FVs.html#tyCoVarsOfCo"><span class="hs-identifier hs-var">tyCoVarsOfCo</span></a></span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680968966"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968964"><span class="hs-identifier hs-var">args</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Expr b -&gt; AltCon -&gt; [Id] -&gt; Bool
</span><a href="#local-6989586621680968975"><span class="hs-identifier hs-var">check_eq</span></a></span><span> </span><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680968967"><span class="hs-identifier hs-var">rhs</span></a></span><span> </span><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680968965"><span class="hs-identifier hs-var">con</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968964"><span class="hs-identifier hs-var">args</span></a></span><span>
</span><span id="line-2284"></span><span>    </span><span class="annot"><a href="#local-6989586621680968975"><span class="hs-identifier hs-var">check_eq</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span id="local-6989586621680968963"><span class="annot"><span class="annottext">Tickish Id
</span><a href="#local-6989586621680968963"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span id="local-6989586621680968962"><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680968962"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680968961"><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680968961"><span class="hs-identifier hs-var">alt</span></a></span></span><span> </span><span id="local-6989586621680968960"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968960"><span class="hs-identifier hs-var">args</span></a></span></span><span>
</span><span id="line-2285"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Tickish Id -&gt; Bool
forall id. Tickish id -&gt; Bool
</span><a href="GHC.Core.html#tickishFloatable"><span class="hs-identifier hs-var">tickishFloatable</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id
</span><a href="#local-6989586621680968963"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Expr b -&gt; AltCon -&gt; [Id] -&gt; Bool
</span><a href="#local-6989586621680968975"><span class="hs-identifier hs-var">check_eq</span></a></span><span> </span><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680968962"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680968961"><span class="hs-identifier hs-var">alt</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968960"><span class="hs-identifier hs-var">args</span></a></span><span>
</span><span id="line-2286"></span><span>
</span><span id="line-2287"></span><span>    </span><span class="annot"><a href="#local-6989586621680968975"><span class="hs-identifier hs-var">check_eq</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lit"><span class="hs-identifier hs-type">Lit</span></a></span><span> </span><span id="local-6989586621680968959"><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680968959"><span class="hs-identifier hs-var">lit</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#LitAlt"><span class="hs-identifier hs-type">LitAlt</span></a></span><span> </span><span id="local-6989586621680968957"><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680968957"><span class="hs-identifier hs-var">lit'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Id]
</span><span class="hs-identifier">_</span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680968959"><span class="hs-identifier hs-var">lit</span></a></span><span> </span><span class="annot"><span class="annottext">Literal -&gt; Literal -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680968957"><span class="hs-identifier hs-var">lit'</span></a></span><span>
</span><span id="line-2288"></span><span>    </span><span class="annot"><a href="#local-6989586621680968975"><span class="hs-identifier hs-var">check_eq</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680968956"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968956"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">AltCon
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968956"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Id -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968992"><span class="hs-identifier hs-var">case_bndr</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-2289"></span><span>    </span><span class="annot"><a href="#local-6989586621680968975"><span class="hs-identifier hs-var">check_eq</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680968955"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968955"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span>   </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#DataAlt"><span class="hs-identifier hs-type">DataAlt</span></a></span><span> </span><span id="local-6989586621680968953"><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680968953"><span class="hs-identifier hs-var">con</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680968952"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968952"><span class="hs-identifier hs-var">args</span></a></span></span><span>
</span><span id="line-2290"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[OutType] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[OutType]
</span><a href="#local-6989586621680968951"><span class="hs-identifier hs-var">arg_tys</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968952"><span class="hs-identifier hs-var">args</span></a></span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968955"><span class="hs-identifier hs-var">v</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Id -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">DataCon -&gt; Id
</span><a href="GHC.Core.DataCon.html#dataConWorkId"><span class="hs-identifier hs-var">dataConWorkId</span></a></span><span> </span><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680968953"><span class="hs-identifier hs-var">con</span></a></span><span>
</span><span id="line-2291"></span><span>                                             </span><span class="hs-comment">-- Optimisation only</span><span>
</span><span id="line-2292"></span><span>    </span><span class="annot"><a href="#local-6989586621680968975"><span class="hs-identifier hs-var">check_eq</span></a></span><span> </span><span id="local-6989586621680968950"><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680968950"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>        </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#DataAlt"><span class="hs-identifier hs-type">DataAlt</span></a></span><span> </span><span id="local-6989586621680968949"><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680968949"><span class="hs-identifier hs-var">con</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680968948"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968948"><span class="hs-identifier hs-var">args</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Tickish Id -&gt; Bool) -&gt; Expr b -&gt; Expr b -&gt; Bool
forall b. (Tickish Id -&gt; Bool) -&gt; Expr b -&gt; Expr b -&gt; Bool
</span><a href="GHC.Core.Utils.html#cheapEqExpr%27"><span class="hs-identifier hs-var">cheapEqExpr'</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Id -&gt; Bool
forall id. Tickish id -&gt; Bool
</span><a href="GHC.Core.html#tickishFloatable"><span class="hs-identifier hs-var">tickishFloatable</span></a></span><span> </span><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680968950"><span class="hs-identifier hs-var">rhs</span></a></span><span> </span><span class="annot"><span class="annottext">(Expr b -&gt; Bool) -&gt; Expr b -&gt; Bool
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-2293"></span><span>                                             </span><span class="annot"><span class="annottext">DataCon -&gt; [OutType] -&gt; [Id] -&gt; Expr b
forall b. DataCon -&gt; [OutType] -&gt; [Id] -&gt; Expr b
</span><a href="GHC.Core.html#mkConApp2"><span class="hs-identifier hs-var">mkConApp2</span></a></span><span> </span><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680968949"><span class="hs-identifier hs-var">con</span></a></span><span> </span><span class="annot"><span class="annottext">[OutType]
</span><a href="#local-6989586621680968951"><span class="hs-identifier hs-var">arg_tys</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968948"><span class="hs-identifier hs-var">args</span></a></span><span>
</span><span id="line-2294"></span><span>    </span><span class="annot"><a href="#local-6989586621680968975"><span class="hs-identifier hs-var">check_eq</span></a></span><span> </span><span class="annot"><span class="annottext">Expr b
</span><span class="hs-identifier">_</span></span><span>          </span><span class="annot"><span class="annottext">AltCon
</span><span class="hs-identifier">_</span></span><span>             </span><span class="annot"><span class="annottext">[Id]
</span><span class="hs-identifier">_</span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-2295"></span><span>
</span><span id="line-2296"></span><span>    </span><span id="local-6989586621680968951"><span class="annot"><span class="annottext">arg_tys :: [OutType]
</span><a href="#local-6989586621680968951"><span class="hs-identifier hs-var hs-var">arg_tys</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OutType -&gt; [OutType]
</span><a href="GHC.Core.Type.html#tyConAppArgs"><span class="hs-identifier hs-var">tyConAppArgs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OutType
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968992"><span class="hs-identifier hs-var">case_bndr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2297"></span><span>
</span><span id="line-2298"></span><span>        </span><span class="hs-comment">-- Note [RHS casts]</span><span>
</span><span id="line-2299"></span><span>        </span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-2300"></span><span>        </span><span class="hs-comment">-- We've seen this:</span><span>
</span><span id="line-2301"></span><span>        </span><span class="hs-comment">--      case e of x { _ -&gt; x `cast` c }</span><span>
</span><span id="line-2302"></span><span>        </span><span class="hs-comment">-- And we definitely want to eliminate this case, to give</span><span>
</span><span id="line-2303"></span><span>        </span><span class="hs-comment">--      e `cast` c</span><span>
</span><span id="line-2304"></span><span>        </span><span class="hs-comment">-- So we throw away the cast from the RHS, and reconstruct</span><span>
</span><span id="line-2305"></span><span>        </span><span class="hs-comment">-- it at the other end.  All the RHS casts must be the same</span><span>
</span><span id="line-2306"></span><span>        </span><span class="hs-comment">-- if (all identity_alt alts) holds.</span><span>
</span><span id="line-2307"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-2308"></span><span>        </span><span class="hs-comment">-- Don't worry about nested casts, because the simplifier combines them</span><span>
</span><span id="line-2309"></span><span>
</span><span id="line-2310"></span><span>    </span><span id="local-6989586621680968985"><span class="annot"><span class="annottext">re_cast :: Expr b -&gt; Expr b -&gt; Expr b
</span><a href="#local-6989586621680968985"><span class="hs-identifier hs-var hs-var">re_cast</span></a></span></span><span> </span><span id="local-6989586621680968944"><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680968944"><span class="hs-identifier hs-var">scrut</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-type">Cast</span></a></span><span> </span><span id="local-6989586621680968943"><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680968943"><span class="hs-identifier hs-var">rhs</span></a></span></span><span> </span><span id="local-6989586621680968942"><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680968942"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr b -&gt; OutCoercion -&gt; Expr b
forall b. Expr b -&gt; OutCoercion -&gt; Expr b
</span><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-var">Cast</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Expr b -&gt; Expr b -&gt; Expr b
</span><a href="#local-6989586621680968985"><span class="hs-identifier hs-var">re_cast</span></a></span><span> </span><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680968944"><span class="hs-identifier hs-var">scrut</span></a></span><span> </span><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680968943"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">OutCoercion
</span><a href="#local-6989586621680968942"><span class="hs-identifier hs-var">co</span></a></span><span>
</span><span id="line-2311"></span><span>    </span><span class="annot"><a href="#local-6989586621680968985"><span class="hs-identifier hs-var">re_cast</span></a></span><span> </span><span id="local-6989586621680968941"><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680968941"><span class="hs-identifier hs-var">scrut</span></a></span></span><span> </span><span class="annot"><span class="annottext">Expr b
</span><span class="hs-identifier">_</span></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr b
</span><a href="#local-6989586621680968941"><span class="hs-identifier hs-var">scrut</span></a></span><span>
</span><span id="line-2312"></span><span>
</span><span id="line-2313"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase1"><span class="hs-identifier hs-var">mkCase1</span></a></span><span> </span><span id="local-6989586621680968940"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680968940"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680968939"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968939"><span class="hs-identifier hs-var">scrut</span></a></span></span><span> </span><span id="local-6989586621680968938"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968938"><span class="hs-identifier hs-var">bndr</span></a></span></span><span> </span><span id="local-6989586621680968937"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680968937"><span class="hs-identifier hs-var">alts_ty</span></a></span></span><span> </span><span id="local-6989586621680968936"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968936"><span class="hs-identifier hs-var">alts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Expr Id -&gt; Id -&gt; OutType -&gt; [InAlt] -&gt; SimplM (Expr Id)
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase2"><span class="hs-identifier hs-var">mkCase2</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680968940"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968939"><span class="hs-identifier hs-var">scrut</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968938"><span class="hs-identifier hs-var">bndr</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680968937"><span class="hs-identifier hs-var">alts_ty</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968936"><span class="hs-identifier hs-var">alts</span></a></span><span>
</span><span id="line-2314"></span><span>
</span><span id="line-2315"></span><span class="hs-comment">--------------------------------------------------</span><span>
</span><span id="line-2316"></span><span class="hs-comment">--      2. Scrutinee Constant Folding</span><span>
</span><span id="line-2317"></span><span class="hs-comment">--------------------------------------------------</span><span>
</span><span id="line-2318"></span><span>
</span><span id="line-2319"></span><span id="mkCase2"><span class="annot"><span class="annottext">mkCase2 :: DynFlags -&gt; Expr Id -&gt; Id -&gt; OutType -&gt; [InAlt] -&gt; SimplM (Expr Id)
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase2"><span class="hs-identifier hs-var hs-var">mkCase2</span></a></span></span><span> </span><span id="local-6989586621680968935"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680968935"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680968934"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968934"><span class="hs-identifier hs-var">scrut</span></a></span></span><span> </span><span id="local-6989586621680968933"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968933"><span class="hs-identifier hs-var">bndr</span></a></span></span><span> </span><span id="local-6989586621680968932"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680968932"><span class="hs-identifier hs-var">alts_ty</span></a></span></span><span> </span><span id="local-6989586621680968931"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968931"><span class="hs-identifier hs-var">alts</span></a></span></span><span>
</span><span id="line-2320"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-comment">-- See Note [Scrutinee Constant Folding]</span><span>
</span><span id="line-2321"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968931"><span class="hs-identifier hs-var">alts</span></a></span><span> </span><span class="hs-keyword">of</span><span>  </span><span class="hs-comment">-- Not if there is just a DEFAULT alternative</span><span>
</span><span id="line-2322"></span><span>      </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="annottext">AltCon
</span><a href="GHC.Core.html#DEFAULT"><span class="hs-identifier hs-var">DEFAULT</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">[Id]
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Expr Id
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-2323"></span><span>      </span><span class="annot"><span class="annottext">[InAlt]
</span><span class="hs-identifier">_</span></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-2324"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">GeneralFlag -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#gopt"><span class="hs-identifier hs-var">gopt</span></a></span><span> </span><span class="annot"><span class="annottext">GeneralFlag
</span><a href="GHC.Driver.Flags.html#Opt_CaseFolding"><span class="hs-identifier hs-var">Opt_CaseFolding</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680968935"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-2325"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680968929"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968929"><span class="hs-identifier hs-var">scrut'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680968928"><span class="annot"><span class="annottext">AltCon -&gt; Maybe AltCon
</span><a href="#local-6989586621680968928"><span class="hs-identifier hs-var">tx_con</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680968927"><span class="annot"><span class="annottext">Id -&gt; Expr Id
</span><a href="#local-6989586621680968927"><span class="hs-identifier hs-var">mk_orig</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Platform
-&gt; Expr Id
-&gt; Maybe (Expr Id, AltCon -&gt; Maybe AltCon, Id -&gt; Expr Id)
</span><a href="GHC.Core.Opt.ConstantFold.html#caseRules"><span class="hs-identifier hs-var">caseRules</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DynFlags -&gt; Platform
</span><a href="GHC.Driver.Session.html#targetPlatform"><span class="hs-identifier hs-var hs-var">targetPlatform</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680968935"><span class="hs-identifier hs-var">dflags</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968934"><span class="hs-identifier hs-var">scrut</span></a></span><span>
</span><span id="line-2326"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680968924"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968924"><span class="hs-identifier hs-var">bndr'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FastString -&gt; OutType -&gt; OutType -&gt; SimplM Id
</span><a href="GHC.Core.Opt.Simplify.Monad.html#newId"><span class="hs-identifier hs-var">newId</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; FastString
</span><a href="GHC.Data.FastString.html#fsLit"><span class="hs-identifier hs-var">fsLit</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;lwild&quot;</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="GHC.Core.Type.html#Many"><span class="hs-identifier hs-var">Many</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Expr Id -&gt; OutType
</span><a href="GHC.Core.Utils.html#exprType"><span class="hs-identifier hs-var">exprType</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968929"><span class="hs-identifier hs-var">scrut'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2327"></span><span>
</span><span id="line-2328"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621680968920"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968920"><span class="hs-identifier hs-var">alts'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(InAlt -&gt; SimplM (Maybe InAlt)) -&gt; [InAlt] -&gt; SimplM [InAlt]
forall (m :: * -&gt; *) a b.
Applicative m =&gt;
(a -&gt; m (Maybe b)) -&gt; [a] -&gt; m [b]
</span><a href="GHC.Utils.Monad.html#mapMaybeM"><span class="hs-identifier hs-var">mapMaybeM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(AltCon -&gt; Maybe AltCon)
-&gt; (Id -&gt; Expr Id) -&gt; Id -&gt; InAlt -&gt; SimplM (Maybe InAlt)
</span><a href="#local-6989586621680968918"><span class="hs-identifier hs-var">tx_alt</span></a></span><span> </span><span class="annot"><span class="annottext">AltCon -&gt; Maybe AltCon
</span><a href="#local-6989586621680968928"><span class="hs-identifier hs-var">tx_con</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Expr Id
</span><a href="#local-6989586621680968927"><span class="hs-identifier hs-var">mk_orig</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968924"><span class="hs-identifier hs-var">bndr'</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968931"><span class="hs-identifier hs-var">alts</span></a></span><span>
</span><span id="line-2329"></span><span>                  </span><span class="hs-comment">-- mapMaybeM: discard unreachable alternatives</span><span>
</span><span id="line-2330"></span><span>                  </span><span class="hs-comment">-- See Note [Unreachable caseRules alternatives]</span><span>
</span><span id="line-2331"></span><span>                  </span><span class="hs-comment">-- in GHC.Core.Opt.ConstantFold</span><span>
</span><span id="line-2332"></span><span>
</span><span id="line-2333"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Expr Id -&gt; Id -&gt; OutType -&gt; [InAlt] -&gt; SimplM (Expr Id)
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase3"><span class="hs-identifier hs-var">mkCase3</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680968935"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968929"><span class="hs-identifier hs-var">scrut'</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968924"><span class="hs-identifier hs-var">bndr'</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680968932"><span class="hs-identifier hs-var">alts_ty</span></a></span><span> </span><span class="annot"><span class="annottext">([InAlt] -&gt; SimplM (Expr Id)) -&gt; [InAlt] -&gt; SimplM (Expr Id)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-2334"></span><span>         </span><span class="annot"><span class="annottext">[InAlt] -&gt; [InAlt]
</span><a href="#local-6989586621680968917"><span class="hs-identifier hs-var">add_default</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[InAlt] -&gt; [InAlt]
</span><a href="#local-6989586621680968916"><span class="hs-identifier hs-var">re_sort</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968920"><span class="hs-identifier hs-var">alts'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2335"></span><span>       </span><span class="hs-special">}</span><span>
</span><span id="line-2336"></span><span>
</span><span id="line-2337"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-2338"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; Expr Id -&gt; Id -&gt; OutType -&gt; [InAlt] -&gt; SimplM (Expr Id)
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase3"><span class="hs-identifier hs-var">mkCase3</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680968935"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968934"><span class="hs-identifier hs-var">scrut</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968933"><span class="hs-identifier hs-var">bndr</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680968932"><span class="hs-identifier hs-var">alts_ty</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968931"><span class="hs-identifier hs-var">alts</span></a></span><span>
</span><span id="line-2339"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-2340"></span><span>    </span><span class="hs-comment">-- We need to keep the correct association between the scrutinee and its</span><span>
</span><span id="line-2341"></span><span>    </span><span class="hs-comment">-- binder if the latter isn't dead. Hence we wrap rhs of alternatives with</span><span>
</span><span id="line-2342"></span><span>    </span><span class="hs-comment">-- &quot;let bndr = ... in&quot;:</span><span>
</span><span id="line-2343"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-2344"></span><span>    </span><span class="hs-comment">--     case v + 10 of y        =====&gt; case v of y</span><span>
</span><span id="line-2345"></span><span>    </span><span class="hs-comment">--        20      -&gt; e1                 10      -&gt; let y = 20     in e1</span><span>
</span><span id="line-2346"></span><span>    </span><span class="hs-comment">--        DEFAULT -&gt; e2                 DEFAULT -&gt; let y = v + 10 in e2</span><span>
</span><span id="line-2347"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-2348"></span><span>    </span><span class="hs-comment">-- Other transformations give: =====&gt; case v of y'</span><span>
</span><span id="line-2349"></span><span>    </span><span class="hs-comment">--                                      10      -&gt; let y = 20      in e1</span><span>
</span><span id="line-2350"></span><span>    </span><span class="hs-comment">--                                      DEFAULT -&gt; let y = y' + 10 in e2</span><span>
</span><span id="line-2351"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-2352"></span><span>    </span><span class="hs-comment">-- This wrapping is done in tx_alt; we use mk_orig, returned by caseRules,</span><span>
</span><span id="line-2353"></span><span>    </span><span class="hs-comment">-- to construct an expression equivalent to the original one, for use</span><span>
</span><span id="line-2354"></span><span>    </span><span class="hs-comment">-- in the DEFAULT case</span><span>
</span><span id="line-2355"></span><span>
</span><span id="line-2356"></span><span>    </span><span class="annot"><a href="#local-6989586621680968918"><span class="hs-identifier hs-type">tx_alt</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#AltCon"><span class="hs-identifier hs-type">AltCon</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.html#AltCon"><span class="hs-identifier hs-type">AltCon</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span>
</span><span id="line-2357"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreAlt"><span class="hs-identifier hs-type">CoreAlt</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.Simplify.Monad.html#SimplM"><span class="hs-identifier hs-type">SimplM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.html#CoreAlt"><span class="hs-identifier hs-type">CoreAlt</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2358"></span><span>    </span><span id="local-6989586621680968918"><span class="annot"><span class="annottext">tx_alt :: (AltCon -&gt; Maybe AltCon)
-&gt; (Id -&gt; Expr Id) -&gt; Id -&gt; InAlt -&gt; SimplM (Maybe InAlt)
</span><a href="#local-6989586621680968918"><span class="hs-identifier hs-var hs-var">tx_alt</span></a></span></span><span> </span><span id="local-6989586621680968914"><span class="annot"><span class="annottext">AltCon -&gt; Maybe AltCon
</span><a href="#local-6989586621680968914"><span class="hs-identifier hs-var">tx_con</span></a></span></span><span> </span><span id="local-6989586621680968913"><span class="annot"><span class="annottext">Id -&gt; Expr Id
</span><a href="#local-6989586621680968913"><span class="hs-identifier hs-var">mk_orig</span></a></span></span><span> </span><span id="local-6989586621680968912"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968912"><span class="hs-identifier hs-var">new_bndr</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680968911"><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680968911"><span class="hs-identifier hs-var">con</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680968910"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968910"><span class="hs-identifier hs-var">bs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680968909"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968909"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-2359"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">AltCon -&gt; Maybe AltCon
</span><a href="#local-6989586621680968914"><span class="hs-identifier hs-var">tx_con</span></a></span><span> </span><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680968911"><span class="hs-identifier hs-var">con</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-2360"></span><span>          </span><span class="annot"><span class="annottext">Maybe AltCon
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe InAlt -&gt; SimplM (Maybe InAlt)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe InAlt
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-2361"></span><span>          </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680968908"><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680968908"><span class="hs-identifier hs-var">con'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680968907"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968907"><span class="hs-identifier hs-var">bs'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Id -&gt; AltCon -&gt; SimplM [Id]
forall {m :: * -&gt; *}. MonadUnique m =&gt; Id -&gt; AltCon -&gt; m [Id]
</span><a href="#local-6989586621680968906"><span class="hs-identifier hs-var">mk_new_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968912"><span class="hs-identifier hs-var">new_bndr</span></a></span><span> </span><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680968908"><span class="hs-identifier hs-var">con'</span></a></span><span>
</span><span id="line-2362"></span><span>                          </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Maybe InAlt -&gt; SimplM (Maybe InAlt)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">InAlt -&gt; Maybe InAlt
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680968908"><span class="hs-identifier hs-var">con'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968907"><span class="hs-identifier hs-var">bs'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968905"><span class="hs-identifier hs-var">rhs'</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-2363"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-2364"></span><span>        </span><span id="local-6989586621680968905"><span class="annot"><span class="annottext">rhs' :: Expr Id
</span><a href="#local-6989586621680968905"><span class="hs-identifier hs-var hs-var">rhs'</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Id.html#isDeadBinder"><span class="hs-identifier hs-var">isDeadBinder</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968933"><span class="hs-identifier hs-var">bndr</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968909"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-2365"></span><span>             </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Expr Id -&gt; Expr Id -&gt; Expr Id
</span><a href="GHC.Core.Utils.html#bindNonRec"><span class="hs-identifier hs-var">bindNonRec</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968933"><span class="hs-identifier hs-var">bndr</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968903"><span class="hs-identifier hs-var">orig_val</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968909"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-2366"></span><span>
</span><span id="line-2367"></span><span>        </span><span id="local-6989586621680968903"><span class="annot"><span class="annottext">orig_val :: Expr Id
</span><a href="#local-6989586621680968903"><span class="hs-identifier hs-var hs-var">orig_val</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680968911"><span class="hs-identifier hs-var">con</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-2368"></span><span>                      </span><span class="annot"><span class="annottext">AltCon
</span><a href="GHC.Core.html#DEFAULT"><span class="hs-identifier hs-var">DEFAULT</span></a></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Expr Id
</span><a href="#local-6989586621680968913"><span class="hs-identifier hs-var">mk_orig</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968912"><span class="hs-identifier hs-var">new_bndr</span></a></span><span>
</span><span id="line-2369"></span><span>                      </span><span class="annot"><a href="GHC.Core.html#LitAlt"><span class="hs-identifier hs-type">LitAlt</span></a></span><span> </span><span id="local-6989586621680968902"><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680968902"><span class="hs-identifier hs-var">l</span></a></span></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Literal -&gt; Expr Id
forall b. Literal -&gt; Expr b
</span><a href="GHC.Core.html#Lit"><span class="hs-identifier hs-var">Lit</span></a></span><span> </span><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680968902"><span class="hs-identifier hs-var">l</span></a></span><span>
</span><span id="line-2370"></span><span>                      </span><span class="annot"><a href="GHC.Core.html#DataAlt"><span class="hs-identifier hs-type">DataAlt</span></a></span><span> </span><span id="local-6989586621680968901"><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680968901"><span class="hs-identifier hs-var">dc</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DataCon -&gt; [OutType] -&gt; [Id] -&gt; Expr Id
forall b. DataCon -&gt; [OutType] -&gt; [Id] -&gt; Expr b
</span><a href="GHC.Core.html#mkConApp2"><span class="hs-identifier hs-var">mkConApp2</span></a></span><span> </span><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680968901"><span class="hs-identifier hs-var">dc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">OutType -&gt; [OutType]
</span><a href="GHC.Core.Type.html#tyConAppArgs"><span class="hs-identifier hs-var">tyConAppArgs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OutType
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968933"><span class="hs-identifier hs-var">bndr</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968910"><span class="hs-identifier hs-var">bs</span></a></span><span>
</span><span id="line-2371"></span><span>
</span><span id="line-2372"></span><span>    </span><span id="local-6989586621680968906"><span class="annot"><span class="annottext">mk_new_bndrs :: Id -&gt; AltCon -&gt; m [Id]
</span><a href="#local-6989586621680968906"><span class="hs-identifier hs-var hs-var">mk_new_bndrs</span></a></span></span><span> </span><span id="local-6989586621680968893"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968893"><span class="hs-identifier hs-var">new_bndr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#DataAlt"><span class="hs-identifier hs-type">DataAlt</span></a></span><span> </span><span id="local-6989586621680968892"><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680968892"><span class="hs-identifier hs-var">dc</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-2373"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DataCon -&gt; Bool
</span><a href="GHC.Core.DataCon.html#isNullaryRepDataCon"><span class="hs-identifier hs-var">isNullaryRepDataCon</span></a></span><span> </span><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680968892"><span class="hs-identifier hs-var">dc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2374"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-comment">-- For non-nullary data cons we must invent some fake binders</span><span>
</span><span id="line-2375"></span><span>        </span><span class="hs-comment">-- See Note [caseRules for dataToTag] in GHC.Core.Opt.ConstantFold</span><span>
</span><span id="line-2376"></span><span>        </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621680968891"><span class="annot"><span class="annottext">[Unique]
</span><a href="#local-6989586621680968891"><span class="hs-identifier hs-var">us</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">m [Unique]
forall (m :: * -&gt; *). MonadUnique m =&gt; m [Unique]
</span><a href="GHC.Types.Unique.Supply.html#getUniquesM"><span class="hs-identifier hs-var">getUniquesM</span></a></span><span>
</span><span id="line-2377"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680968890"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968890"><span class="hs-identifier hs-var">ex_tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680968889"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968889"><span class="hs-identifier hs-var">arg_ids</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Unique] -&gt; OutType -&gt; DataCon -&gt; [OutType] -&gt; ([Id], [Id])
</span><a href="GHC.Core.Utils.html#dataConRepInstPat"><span class="hs-identifier hs-var">dataConRepInstPat</span></a></span><span> </span><span class="annot"><span class="annottext">[Unique]
</span><a href="#local-6989586621680968891"><span class="hs-identifier hs-var">us</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OutType
</span><a href="GHC.Types.Id.html#idMult"><span class="hs-identifier hs-var">idMult</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968893"><span class="hs-identifier hs-var">new_bndr</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680968892"><span class="hs-identifier hs-var">dc</span></a></span><span>
</span><span id="line-2378"></span><span>                                        </span><span class="hs-special">(</span><span class="annot"><span class="annottext">OutType -&gt; [OutType]
</span><a href="GHC.Core.Type.html#tyConAppArgs"><span class="hs-identifier hs-var">tyConAppArgs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OutType
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968893"><span class="hs-identifier hs-var">new_bndr</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-2379"></span><span>           </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; m [Id]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968890"><span class="hs-identifier hs-var">ex_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; [Id] -&gt; [Id]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968889"><span class="hs-identifier hs-var">arg_ids</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-2380"></span><span>    </span><span class="annot"><a href="#local-6989586621680968906"><span class="hs-identifier hs-var">mk_new_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">AltCon
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Id] -&gt; m [Id]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-2381"></span><span>
</span><span id="line-2382"></span><span>    </span><span class="annot"><a href="#local-6989586621680968916"><span class="hs-identifier hs-type">re_sort</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreAlt"><span class="hs-identifier hs-type">CoreAlt</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreAlt"><span class="hs-identifier hs-type">CoreAlt</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-2383"></span><span>    </span><span class="hs-comment">-- Sort the alternatives to re-establish</span><span>
</span><span id="line-2384"></span><span>    </span><span class="hs-comment">-- GHC.Core Note [Case expression invariants]</span><span>
</span><span id="line-2385"></span><span>    </span><span id="local-6989586621680968916"><span class="annot"><span class="annottext">re_sort :: [InAlt] -&gt; [InAlt]
</span><a href="#local-6989586621680968916"><span class="hs-identifier hs-var hs-var">re_sort</span></a></span></span><span> </span><span id="local-6989586621680968887"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968887"><span class="hs-identifier hs-var">alts</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(InAlt -&gt; InAlt -&gt; Ordering) -&gt; [InAlt] -&gt; [InAlt]
forall a. (a -&gt; a -&gt; Ordering) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/Data.OldList.html#sortBy"><span class="hs-identifier hs-var">sortBy</span></a></span><span> </span><span class="annot"><span class="annottext">InAlt -&gt; InAlt -&gt; Ordering
forall a b. (AltCon, a, b) -&gt; (AltCon, a, b) -&gt; Ordering
</span><a href="GHC.Core.html#cmpAlt"><span class="hs-identifier hs-var">cmpAlt</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968887"><span class="hs-identifier hs-var">alts</span></a></span><span>
</span><span id="line-2386"></span><span>
</span><span id="line-2387"></span><span>    </span><span class="annot"><a href="#local-6989586621680968917"><span class="hs-identifier hs-type">add_default</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreAlt"><span class="hs-identifier hs-type">CoreAlt</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#CoreAlt"><span class="hs-identifier hs-type">CoreAlt</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-2388"></span><span>    </span><span class="hs-comment">-- See Note [Literal cases]</span><span>
</span><span id="line-2389"></span><span>    </span><span id="local-6989586621680968917"><span class="annot"><span class="annottext">add_default :: [InAlt] -&gt; [InAlt]
</span><a href="#local-6989586621680968917"><span class="hs-identifier hs-var hs-var">add_default</span></a></span></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#LitAlt"><span class="hs-identifier hs-type">LitAlt</span></a></span><span> </span><span class="hs-special">{</span><span class="hs-special">}</span><span class="hs-special">,</span><span> </span><span id="local-6989586621680968885"><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968885"><span class="hs-identifier hs-var">bs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680968884"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968884"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680968883"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968883"><span class="hs-identifier hs-var">alts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AltCon
</span><a href="GHC.Core.html#DEFAULT"><span class="hs-identifier hs-var">DEFAULT</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Id]
</span><a href="#local-6989586621680968885"><span class="hs-identifier hs-var">bs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968884"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">InAlt -&gt; [InAlt] -&gt; [InAlt]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968883"><span class="hs-identifier hs-var">alts</span></a></span><span>
</span><span id="line-2390"></span><span>    </span><span class="annot"><a href="#local-6989586621680968917"><span class="hs-identifier hs-var">add_default</span></a></span><span> </span><span id="local-6989586621680968882"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968882"><span class="hs-identifier hs-var">alts</span></a></span></span><span>                          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968882"><span class="hs-identifier hs-var">alts</span></a></span><span>
</span><span id="line-2391"></span><span>
</span><span id="line-2392"></span><span class="hs-comment">{- Note [Literal cases]
~~~~~~~~~~~~~~~~~~~~~~~
If we have
  case tagToEnum (a &gt;# b) of
     False -&gt; e1
     True  -&gt; e2

then caseRules for TagToEnum will turn it into
  case tagToEnum (a &gt;# b) of
     0# -&gt; e1
     1# -&gt; e2

Since the case is exhaustive (all cases are) we can convert it to
  case tagToEnum (a &gt;# b) of
     DEFAULT -&gt; e1
     1#      -&gt; e2

This may generate sligthtly better code (although it should not, since
all cases are exhaustive) and/or optimise better.  I'm not certain that
it's necessary, but currently we do make this change.  We do it here,
NOT in the TagToEnum rules (see &quot;Beware&quot; in Note [caseRules for tagToEnum]
in GHC.Core.Opt.ConstantFold)
-}</span><span>
</span><span id="line-2415"></span><span>
</span><span id="line-2416"></span><span class="hs-comment">--------------------------------------------------</span><span>
</span><span id="line-2417"></span><span class="hs-comment">--      Catch-all</span><span>
</span><span id="line-2418"></span><span class="hs-comment">--------------------------------------------------</span><span>
</span><span id="line-2419"></span><span id="mkCase3"><span class="annot"><span class="annottext">mkCase3 :: DynFlags -&gt; Expr Id -&gt; Id -&gt; OutType -&gt; [InAlt] -&gt; SimplM (Expr Id)
</span><a href="GHC.Core.Opt.Simplify.Utils.html#mkCase3"><span class="hs-identifier hs-var hs-var">mkCase3</span></a></span></span><span> </span><span id="local-6989586621680968881"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680968881"><span class="hs-identifier hs-var">_dflags</span></a></span></span><span> </span><span id="local-6989586621680968880"><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968880"><span class="hs-identifier hs-var">scrut</span></a></span></span><span> </span><span id="local-6989586621680968879"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968879"><span class="hs-identifier hs-var">bndr</span></a></span></span><span> </span><span id="local-6989586621680968878"><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680968878"><span class="hs-identifier hs-var">alts_ty</span></a></span></span><span> </span><span id="local-6989586621680968877"><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968877"><span class="hs-identifier hs-var">alts</span></a></span></span><span>
</span><span id="line-2420"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Expr Id -&gt; SimplM (Expr Id)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Expr Id -&gt; Id -&gt; OutType -&gt; [InAlt] -&gt; Expr Id
forall b. Expr b -&gt; b -&gt; OutType -&gt; [Alt b] -&gt; Expr b
</span><a href="GHC.Core.html#Case"><span class="hs-identifier hs-var">Case</span></a></span><span> </span><span class="annot"><span class="annottext">Expr Id
</span><a href="#local-6989586621680968880"><span class="hs-identifier hs-var">scrut</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968879"><span class="hs-identifier hs-var">bndr</span></a></span><span> </span><span class="annot"><span class="annottext">OutType
</span><a href="#local-6989586621680968878"><span class="hs-identifier hs-var">alts_ty</span></a></span><span> </span><span class="annot"><span class="annottext">[InAlt]
</span><a href="#local-6989586621680968877"><span class="hs-identifier hs-var">alts</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2421"></span><span>
</span><span id="line-2422"></span><span class="hs-comment">-- See Note [Exitification] and Note [Do not inline exit join points] in</span><span>
</span><span id="line-2423"></span><span class="hs-comment">-- GHC.Core.Opt.Exitify</span><span>
</span><span id="line-2424"></span><span class="hs-comment">-- This lives here (and not in Id) because occurrence info is only valid on</span><span>
</span><span id="line-2425"></span><span class="hs-comment">-- InIds, so it's crucial that isExitJoinId is only called on freshly</span><span>
</span><span id="line-2426"></span><span class="hs-comment">-- occ-analysed code. It's not a generic function you can call anywhere.</span><span>
</span><span id="line-2427"></span><span class="annot"><a href="GHC.Core.Opt.Simplify.Utils.html#isExitJoinId"><span class="hs-identifier hs-type">isExitJoinId</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-2428"></span><span id="isExitJoinId"><span class="annot"><span class="annottext">isExitJoinId :: Id -&gt; Bool
</span><a href="GHC.Core.Opt.Simplify.Utils.html#isExitJoinId"><span class="hs-identifier hs-var hs-var">isExitJoinId</span></a></span></span><span> </span><span id="local-6989586621680968875"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968875"><span class="hs-identifier hs-var">id</span></a></span></span><span>
</span><span id="line-2429"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Id.html#isJoinId"><span class="hs-identifier hs-var">isJoinId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968875"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-2430"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">OccInfo -&gt; Bool
</span><a href="GHC.Types.Basic.html#isOneOcc"><span class="hs-identifier hs-var">isOneOcc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OccInfo
</span><a href="GHC.Types.Id.html#idOccInfo"><span class="hs-identifier hs-var">idOccInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968875"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-2431"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">OccInfo -&gt; InsideLam
</span><a href="GHC.Types.Basic.html#occ_in_lam"><span class="hs-identifier hs-var hs-var">occ_in_lam</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; OccInfo
</span><a href="GHC.Types.Id.html#idOccInfo"><span class="hs-identifier hs-var">idOccInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680968875"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">InsideLam -&gt; InsideLam -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">InsideLam
</span><a href="GHC.Types.Basic.html#IsInsideLam"><span class="hs-identifier hs-var">IsInsideLam</span></a></span><span>
</span><span id="line-2432"></span><span>
</span><span id="line-2433"></span><span class="hs-comment">{-
Note [Dead binders]
~~~~~~~~~~~~~~~~~~~~
Note that dead-ness is maintained by the simplifier, so that it is
accurate after simplification as well as before.


Note [Cascading case merge]
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Case merging should cascade in one sweep, because it
happens bottom-up

      case e of a {
        DEFAULT -&gt; case a of b
                      DEFAULT -&gt; case b of c {
                                     DEFAULT -&gt; e
                                     A -&gt; ea
                      B -&gt; eb
        C -&gt; ec
==&gt;
      case e of a {
        DEFAULT -&gt; case a of b
                      DEFAULT -&gt; let c = b in e
                      A -&gt; let c = b in ea
                      B -&gt; eb
        C -&gt; ec
==&gt;
      case e of a {
        DEFAULT -&gt; let b = a in let c = b in e
        A -&gt; let b = a in let c = b in ea
        B -&gt; let b = a in eb
        C -&gt; ec


However here's a tricky case that we still don't catch, and I don't
see how to catch it in one pass:

  case x of c1 { I# a1 -&gt;
  case a1 of c2 -&gt;
    0 -&gt; ...
    DEFAULT -&gt; case x of c3 { I# a2 -&gt;
               case a2 of ...

After occurrence analysis (and its binder-swap) we get this

  case x of c1 { I# a1 -&gt;
  let x = c1 in         -- Binder-swap addition
  case a1 of c2 -&gt;
    0 -&gt; ...
    DEFAULT -&gt; case x of c3 { I# a2 -&gt;
               case a2 of ...

When we simplify the inner case x, we'll see that
x=c1=I# a1.  So we'll bind a2 to a1, and get

  case x of c1 { I# a1 -&gt;
  case a1 of c2 -&gt;
    0 -&gt; ...
    DEFAULT -&gt; case a1 of ...

This is correct, but we can't do a case merge in this sweep
because c2 /= a1.  Reason: the binding c1=I# a1 went inwards
without getting changed to c1=I# c2.

I don't think this is worth fixing, even if I knew how. It'll
all come out in the next pass anyway.
-}</span><span>
</span><span id="line-2500"></span></pre></body></html>